private Vector2 CreateMovementInput(out bool running) { Vector2 controllerForce = Vector2.zero; //The Diagram states that there is no transition from any state to runnning except Walking float runToggle = ControllerState == PlayerControllerState.Walking || ControllerState == PlayerControllerState.Running ? RunToggle.GetActivation() : 0; running = Math.Abs(runToggle) > 0.0001f; //Based on the information wether we are running or not we are selecting the right Speed Values. float mSpeedLeft = running ? RunSpeedLeft : WalkSpeedLeft; float mSpeedRight = running ? RunSpeedRight : WalkSpeedRight; //Get the Input from the InputBindings. float inputLeft = Left.GetActivation(); //Range [0, 1] float inputRight = Right.GetActivation(); //Range [0, 1] if (ControllerState == PlayerControllerState.Falling) { inputRight = inputLeft = 0; } controllerForce.x = -mSpeedLeft * inputLeft; //Move to the Reft controllerForce.x += mSpeedRight * inputRight; //Move to the Right return(controllerForce); }
private Vector2 CreateJumpInput(Vector2 baseInput, out bool jumped) { jumped = false; float jump = Jump.GetActivation() * (IsGrounded ? 1 : 0); //Multiply by 0 if grounded(No jump while not grounded). if (Math.Abs(jump) > 0.0001f) { jumped = true; baseInput.x *= ForwardJumpForce * jump; //Possibility to add a bit of extra Horizontal Velocity when jumping baseInput.y = UpwardJumpForce * jump; //Upwards Motion } return(baseInput); }