//MAKING NEW METHOD FOR MOVEMENT! TOGGLES ON MOVE UNTIL REACHING POSTION void processMove(int index, float distance) { //print("PROCCESING MOVE AT " + index + " " + distance); moveStates x = inputList[index]; if (x == moveStates.LEFT && distance > 0) { transform.position = Vector2.MoveTowards(transform.position, new Vector2(transform.position.x - distance, transform.position.y), step); distance -= step; } else if (x == moveStates.RIGHT && distance > 0) { transform.position = Vector2.MoveTowards(transform.position, new Vector2(transform.position.x + distance, transform.position.y), step); distance -= step; } else if (x == moveStates.UP && distance > 0) { transform.position = Vector2.MoveTowards(transform.position, new Vector2(transform.position.x, transform.position.y + distance), step); distance -= step; } else if (x == moveStates.DOWN && distance > 0) { transform.position = Vector2.MoveTowards(transform.position, new Vector2(transform.position.x, transform.position.y - distance), step); distance -= step; } }
protected void Awake() { controller = this.GetComponent<Prime31.CharacterController2D>(); myPhotonView = this.GetComponent<PhotonView>(); playerInput = this.GetComponent<InputHandler>(); myCollider = this.GetComponent<BoxCollider2D>(); moveState = moveStates.firstJump; }
private void OnTriggerEnter(Collider other) { //If an enemy enters the trigger, add it to the list of the ones present and freak the pig out if (other.CompareTag("Bouncer")) { enemiesPresentInTrigger.Add(other.gameObject); moveState = moveStates.Evading; } }
//Vector3 floorRayAngleOffset; void Awake() { sceneManager = GameObject.FindGameObjectWithTag("SceneManager"); rb = GetComponent <Rigidbody>(); //floorRayAngleOffset = new Vector3(0, 0, 30); myMoveState = moveStates.standing; }
//MAKING NEW METHOD FOR MOVEMENT! TOGGLES ON MOVE UNTIL REACHING POSTION void processMove(int index,float distance) { //print("PROCCESING MOVE AT " + index + " " + distance); moveStates x = inputList[index]; if (x == moveStates.LEFT && distance > 0) { transform.position = Vector2.MoveTowards(transform.position, new Vector2(transform.position.x - distance, transform.position.y), step); distance -= step; } else if (x == moveStates.RIGHT && distance > 0) { transform.position = Vector2.MoveTowards(transform.position, new Vector2(transform.position.x + distance, transform.position.y), step); distance -= step; } else if (x == moveStates.UP && distance > 0) { transform.position = Vector2.MoveTowards(transform.position, new Vector2(transform.position.x, transform.position.y + distance), step); distance -= step; } else if (x == moveStates.DOWN && distance > 0) { transform.position = Vector2.MoveTowards(transform.position, new Vector2(transform.position.x, transform.position.y - distance), step); distance -= step; } //The rate of rotation might change as well as how much it rotates else if (x == moveStates.ROTATE_LEFT) { aim_sprite.transform.RotateAround(transform.position, new Vector3(0, 0, 1), step*10); angle += step*10; offsetNum -= 0.01f; } else if (x == moveStates.ROTATE_RIGHT) { aim_sprite.transform.RotateAround(transform.position, new Vector3(0, 0, 1), -step*10); angle += -step*10; offsetNum -= 0.01f; } else if(x == moveStates.SHOOT && !(hasFired)) { shootTest(); hasFired = true; offsetNum = 0; } else if(x == moveStates.STILL) { offsetNum = 0; } }
// Use this for initialization void Start() { //initial direction decision if (startLeftOrRight) { state = moveStates.RIGHT; } else { state = moveStates.LEFT; } }
void OnTriggerEnter2D(Collider2D other) { // players & enemies don't bounce (possible change needed) if (other.tag != "interactionBox") { // turns slider (need to flip sprite, possible change needed) transform.Rotate(0, 0, 180); // direction decision if (state == moveStates.LEFT) { state = moveStates.RIGHT; } else { state = moveStates.LEFT; } } }
void ChangeStance() { if (Input.GetKeyDown(KeyCode.LeftShift)) { switch (myMoveState) { case moveStates.standing: transform.localScale = new Vector3(1, .5f, 1); myMoveState = moveStates.crouching; break; case moveStates.crouching: transform.localScale = Vector3.one; myMoveState = moveStates.standing; break; default: break; } } }
IEnumerator Move() { //The time since the pig last turned or stood float moveChangeTimer = 0f; while (true) { //get the current state of the pig's movement switch (moveState) { case moveStates.Walking: moveChangeTimer += 0.3f; rigidbody.velocity = transform.forward * pigMoveSpeed * GameController.gameController.gameDifficulty.pigMoveSpeedMultiplier; //if it hits a wall, apply a turn if (Physics.Raycast(transform.position, transform.forward, GameController.gameController.gameSettings.boundsRadius * 1.25f)) { moveChangeTimer = 0f; Debug.Log("Turned due to collision"); transform.Rotate(new Vector3(0f, Random.Range(60f, 180f), 0f)); } //if it walks straight for too long, turn or stand still if (moveChangeTimer > pigMoveChangeFrequency) { float ranNum = Random.Range(0f, 10f); if (ranNum > 6f) { Debug.Log("Turned after " + moveChangeTimer.ToString() + " seconds"); moveChangeTimer = 0f; transform.Rotate(new Vector3(0f, Random.Range(60f, 180f), 0f)); } else if (ranNum < 2f) { moveState = moveStates.Standing; moveChangeTimer = 0f; } } break; case moveStates.Evading: Debug.Log("Freaking " + enemiesPresentInTrigger.Count + " enemies in the trigger!"); Vector3 averageEnemyPosition = new Vector3(0f, 1f, 0f); List <GameObject> enemiesToRemove = new List <GameObject>(); //Assign enemies from trigger to cull (as they will not trigger the on exit code) for (int i = 0; i < enemiesPresentInTrigger.Count; i++) { //Assign Cull if (enemiesPresentInTrigger[i] == null) { break; } else if (Vector3.Distance(enemiesPresentInTrigger[i].transform.position, transform.position) > GameController.gameController.gameSettings.pigDetectionRadius * 1.8f * GameController.gameController.gameDifficulty.pigDetectionRadiusMultiplier) { enemiesToRemove.Add(enemiesPresentInTrigger[i]); //average position for all so the pig can run away averageEnemyPosition += enemiesPresentInTrigger[i].transform.position; } } //Cull loop if (enemiesToRemove.Count != 0) { for (int i = 0; i < enemiesToRemove.Count; i++) { enemiesPresentInTrigger.Remove(enemiesToRemove[i]); } } if (enemiesPresentInTrigger.Count == 0) { moveChangeTimer = 0f; if (Random.Range(0f, 10f) > 5f) { moveState = moveStates.Walking; } else { moveState = moveStates.Standing; } } //Generate the average position of all enemies in the trigger averageEnemyPosition /= enemiesPresentInTrigger.Count + enemiesToRemove.Count; averageEnemyPosition.y = 1f; //turn the pig away from the enemy and have them run transform.LookAt(transform.position - (averageEnemyPosition - transform.position)); Debug.Log(transform.position - (averageEnemyPosition - transform.position)); rigidbody.velocity = transform.forward * pigMoveSpeed * GameController.gameController.gameDifficulty.pigMoveSpeedMultiplier; break; case moveStates.Standing: moveChangeTimer += 0.3f; rigidbody.velocity = Vector3.zero; //if it stands still too long, have it move if (moveChangeTimer > pigMoveChangeFrequency) { float ranNum = Random.Range(0f, 10f); if (ranNum > 3f) { moveChangeTimer = 0f; moveState = moveStates.Walking; } } break; } yield return(new WaitForSeconds(0.3f)); } }
protected Vector3 HandleMovement() { Vector3 velocity = controller.velocity; if (controller.isGrounded) { velocity.y = 0; moveState = moveStates.grounded; } if (Input.GetAxisRaw("Horizontal") > 0) { velocity.x = speed; } else if (Input.GetAxisRaw("Horizontal") < 0) { velocity.x = -speed; } else { velocity.x = 0; } if (moveState != moveStates.secondJump && Input.GetButtonDown("Jump")) { velocity.y = Mathf.Sqrt(2f * jumpHeight * -gravity); if (moveState == moveStates.grounded) { moveState = moveStates.firstJump; } else { moveState = moveStates.secondJump; } } velocity.y += gravity * Time.deltaTime; return velocity; }
protected void Awake() { controller = this.GetComponent<CharacterController2D>(); myPhotonView = this.GetComponent<PhotonView>(); myHealth = this.GetComponent<Health>(); moveState = moveStates.secondJump; fxManager = GameObject.FindObjectOfType<FXManager>(); if(fxManager) { fxManagerPhotonView = fxManager.GetComponent<PhotonView>(); } netMan = GameObject.FindObjectOfType<MovementTestingNetMan>(); netManPhotonView = netMan.GetComponent<PhotonView>(); }
protected Vector3 HandleMovement(InputHandler.InputStruct input) { Vector3 velocity = controller.velocity; // am I grounded? if(moveState != moveStates.crawling && controller.isGrounded) { velocity.y = 0; moveState = moveStates.grounded; } else if(controller.isGrounded) { velocity.y = 0; } // dropping through a platform if(moveState != moveStates.firstJump && input.downDirection && input.action1) { controller.ignoreOneWayPlatformsThisFrame = true; velocity.y = gravity / 2; moveState = moveStates.firstJump; } // ducking if(moveState == moveStates.crawling && !input.downDirection) { // grow hitbox myCollider.size = new Vector2(1f, 1f); myCollider.offset = new Vector2(0f, 0f); // change movestate moveState = moveStates.grounded; } else if(moveState == moveStates.grounded && input.downDirection) { // shrink hitbox myCollider.size = new Vector2(1f, 0.5f); myCollider.offset = new Vector2(0f, -0.25f); // change movestate moveState = moveStates.crawling; } // horizontal velocity if (input.rightDirection) { if(moveState == moveStates.grounded) { velocity.x = speed; } else { velocity.x = speed * airTurnFactor; } facingRight = true; } else if(input.leftDirection) { if (moveState == moveStates.grounded) { velocity.x = -speed; } else { velocity.x = -speed * airTurnFactor; } facingRight = false; } else { velocity.x = 0; } // vertical velocity if (moveState == moveStates.grounded && input.action1) { velocity.y = Mathf.Sqrt(2f * jumpHeight * -gravity); moveState = moveStates.firstJump; } velocity.y += (2f * gravity) * Time.deltaTime; return velocity; }