public override AbstractState HandleUpdate(PlayerStateMachine stateMachine, Animator animator, CharacterMovementController playerController) { if (!playerController.IsJumpingPossible()) { return(PlayerStateMachine.idleState); } if (Input.GetKeyUp(KeyCode.Space)) { float jumpTime = Time.time - jumpTimerStart; float jumpForcePercent = CalculatePercentFromJumpTimer(jumpTime); if (jumpForcePercent > 0) { // JUMP NOW! stateMachine.InstantiateEffect(dustEffect); playerController.OnJumping(jumpForcePercent); float directionX = Input.GetAxisRaw("Horizontal"); if (directionX != 0) { // Spieler will sich beim springen bewegen stateMachine.FlipSprite(directionX); PlayerStateMachine.jumpStartRunningState.InitParameters(directionX); return(PlayerStateMachine.jumpStartRunningState); } else { return(PlayerStateMachine.jumpStartIdleState); } } else { Debug.LogError("Error in PreJumpIdleState: JumpForce <= 0, also kein Sprung möglich!"); return(PlayerStateMachine.idleState); } } else { if (!Input.GetKey(KeyCode.Space)) { Debug.LogError("Error in PreJumpIdleState: Space Taste nicht mehr gedrückt, aber kein KeyUp!"); return(PlayerStateMachine.idleState); } } return(null); }
public override AbstractState HandleUpdate(PlayerStateMachine stateMachine, Animator animator, CharacterMovementController playerController) { float directionX = Input.GetAxisRaw("Horizontal"); if (directionX == 0 || directionX != stateMachine.currentDirectionX || !playerController.IsJumpingPossible()) { // Stopping return(PlayerStateMachine.stoppingState); } if (Input.GetKeyUp(KeyCode.Space)) { float jumpTime = Time.time - jumpTimerStart; float jumpForcePercent = CalculatePercentFromJumpTimer(jumpTime); float moveFactorAirborne = CalculateMoveFactorFromJumpTimer(jumpTime); if (jumpForcePercent > 0) { stateMachine.InstantiateEffect(dustJumpEffect); playerController.OnJumping(jumpForcePercent); PlayerStateMachine.jumpStartRunningState.InitParameters(directionX, moveFactorAirborne); return(PlayerStateMachine.jumpStartRunningState); } else { Debug.LogError("Error in PreJumpIdleState: JumpForce <= 0, also kein Sprung möglich!"); return(PlayerStateMachine.idleState); } } else { if (!Input.GetKey(KeyCode.Space)) { Debug.LogError("Error in PreJumpIdleState: Space Taste nicht mehr gedrückt, aber kein KeyUp!"); return(PlayerStateMachine.runningState); } } // continue moving MoveXGrounded(stateMachine, playerController, moveFactorGrounded); return(null); }