0
\$\begingroup\$

My character's collider only jumps with the animation while walking. And when he runs he gets stuck in the air and can walk in the air.

Here's my script for jumping. At this point I have tried several different jump techniques and have been working on this one thing for over a week. There is nothing wrong with the animations themselves, when he's idle the animation plays but the CharacterController collider stays on the ground.

Animator anim;    


public float jumpSpeed = 8.0F;

     private Vector3 moveDirection = Vector3.zero;

     private CharacterController _charController;
     public float speed = 6.0f;
     public float gravity = 10f;

     private float verticalVelocity;
     private float jumpForce = 5.0f;
     private float gravityJump = 14.0f;

     void Start()
     {
         _charController = GetComponent<CharacterController>();
         anim = GetComponent<Animator>();
     }

     void Update()
     {          

         if (_charController.isGrounded)
         {
             verticalVelocity = -gravityJump * Time.deltaTime;
             if (Input.GetKeyDown(KeyCode.Space))
             {
                 anim.SetTrigger("Jump");
                 float deltaX = Input.GetAxis("Horizontal") * speed;
                 float deltaZ = Input.GetAxis("Vertical") * speed;
                 Vector3 movement = new Vector3(deltaX, 0, deltaZ);
                 movement = Vector3.ClampMagnitude(movement, speed);

                 movement.y = gravity;

                 movement *= Time.deltaTime;
                 movement = transform.TransformDirection(movement);
                 _charController.Move(movement);
                 verticalVelocity = jumpForce;
             }
         }
         else
         {
             verticalVelocity -= gravityJump * Time.deltaTime;
         }

         Vector3 jumpVector = new Vector3(0, verticalVelocity, 0);
         _charController.Move(jumpVector * Time.deltaTime);

     }
 }
\$\endgroup\$
  • 1
    \$\begingroup\$ Can you show us your Animation Controller graph? It sounds like you might be missing transitions between certain states, or have them configured incorrectly. \$\endgroup\$ – DMGregory Jan 15 at 0:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.