- Home /
Question by
neximadev · May 15, 2019 at 09:02 AM ·
character movement
How to allow mid air control using character controller?
I can't figure out why my code doesn't allow for mid air control. Movement and jumping work fine, but I just can't adjust the trajectory once in the air. I used this tutorial: https://www.youtube.com/watch?v=n-KX8AeGK7E
//Determines which direction to move, multiplies by movementSpeed
private void PlayerMovement()
{
float horizInput = Input.GetAxis(horizontalInputName);
float vertInput = Input.GetAxis(verticalInputName);
Vector3 forwardMovement = transform.forward * vertInput;
Vector3 rightMovement = transform.right * horizInput;
//SimpleMove applies Time.deltaTime automatically
charController.SimpleMove(Vector3.ClampMagnitude(forwardMovement + rightMovement, 1f) * movementSpeed);
if ((vertInput != 0 || horizInput != 0) && OnSlope())
charController.Move(Vector3.down * charController.height / 2 * slopeForce * Time.deltaTime);
//Only allows jumping if touching the ground
if(charController.isGrounded)
JumpInput();
}
private void JumpInput()
{
if (Input.GetKeyDown(jumpKey) && !isJumping)
{
isJumping = true;
StartCoroutine(JumpEvent());
}
}
private IEnumerator JumpEvent()
{
//Allows slight mantling onto ledges
charController.slopeLimit = 90f;
float timeInAir = 0.0f;
do
{
float jumpForce = jumpFalloff.Evaluate(timeInAir);
charController.Move(Vector3.up * jumpForce * jumpMultiplier * Time.deltaTime);
timeInAir += Time.deltaTime;
yield return null;
} while (!charController.isGrounded && charController.collisionFlags != CollisionFlags.Above); //Checks the area above the player for ceiling
charController.slopeLimit = 45f;
isJumping = false;
}
Thanks for any help... I'm stuck :(
Comment
Your answer
Follow this Question
Related Questions
Stopping 3rd Person Controller When It Hits Raised Terrtain 0 Answers
Need help with buggy character movement 0 Answers
Third Person Controller: Animates correctly, but can't move 5 Answers
Hungry Shark Evolution Movement 0 Answers
Character and Camera motion smooth in Editor, but jitters in Build 1 Answer