// Moving implementation public void Move(float move, bool jump) { if (movementState.Equals(MovementState.Ground) || _airControll) { Vector2 targetVelocity = new Vector2(move * 10f, _rigidbody.velocity.y); _rigidbody.velocity = Vector2.SmoothDamp(_rigidbody.velocity, targetVelocity, ref _curVelocity, _movementSmoothing); if (movementState.Equals(MovementState.Ground) && move != 0) { movementState = MovementState.Running; } else if (movementState.Equals(MovementState.Running) && move == 0) { movementState = MovementState.Ground; } } if (move > 0 && !_rightFacing) { Flip(); } else if (move < 0 && _rightFacing) { Flip(); } if (!movementState.Equals(MovementState.Jumping) && jump) { movementState = MovementState.Jumping; isGrounded = false; _rigidbody.AddForce(new Vector2(0f, _jumpForce), ForceMode2D.Impulse); } }
protected override bool ShouldSlowDown() { bool slowDown = false; if (GetCurrentState.Equals(AIState.Moving) || GetCurrentState.Equals(AIState.Crossing)) { slowDown = currentMovementState.Equals(MovementState.SlowDown); } return(slowDown); }
private float GetAngleZ(MovementState sideMovementState, float addValue) { float angleZ = parentShip.transform.localEulerAngles.z; float z = parentShip.transform.localEulerAngles.z; if ((angleZ < 20 || angleZ > 300) && sideMovementState.Equals(MovementState.RIGHT)) { z = z + addValue; } else if ((angleZ > 340 || angleZ <= 50) && sideMovementState.Equals(MovementState.LEFT)) { z = z + addValue; } return(z); }
void Update() { foreach (MovementState ms in moveStates) { foreach (string s in ms.enablers) { if (Input.GetButtonDown(s)) { goToState(ms); } } foreach (string s in ms.disablers) { if (Input.GetButtonDown(s)) { goToState(moveStates[0]); } } foreach (string s in ms.toggles) { if (Input.GetButtonDown(s)) { if (currentState.Equals(ms)) { goToState(moveStates [0]); } else { goToState(ms); } } } } charCon.radius = currentState.radius; charCon.height = currentState.height; movement.playerMovement.movementSpeed = currentState.speed; }