Character jumps super high when against a wall.

I don’t know if it is because of friction? When my player is against pretty much any object with a collider and then when I jump it jumps so high. I’ve tried using raycast to ground and that is not helping, also tried the normal controller.IsGrounded and not working either.

So I guess I need to do something with colliders?

Hope this is the right forum.

Your ground check is likely considering the wall to be the ground. Also you might be using GetKey instead of GetKeyDown?

1 Like
 private void Jumping()
    {
        RayToGround();

        if (Input.GetKey(controls.PlayerJumpButton) && playerOnGround)
        {
            playerVelocityY.y += Mathf.Sqrt(jumpForce * -2.0f * gravity);
            currentSpeed = 2f;
        }

        playerVelocityY.y += gravity * Time.deltaTime;
        controller.Move(playerVelocityY * Time.deltaTime);
    }

    RaycastHit hit;
    public GameObject rayOrigin;

    private void RayToGround()
    {
        if(Physics.Raycast(rayOrigin.transform.position, Vector3.down, out hit, rayDistance, ground))
            Debug.DrawRay(rayOrigin.transform.position, Vector3.down * rayDistance, Color.red);

        if(hit.collider != null)
        {
            playerOnGround = true;
            currentSpeed = 5f;
        }
          
        else
            playerOnGround = false;

    }

here’s my code.

Your RayToGround code is the main issue here. Only the Debug.Log call is inside the if statement for the raycast. If the raycast doesn’t hit, the RaycastHit won’t get overwritten. So on line 23 you’re testing an old RaycastHit. Basically once you’re grounded once, you’ll be grounded forever.

You need to do something like this:

    private void RayToGround()
    {
        if(Physics.Raycast(rayOrigin.transform.position, Vector3.down, out hit, rayDistance, ground)) {
            Debug.DrawRay(rayOrigin.transform.position, Vector3.down * rayDistance, Color.red);
            playerOnGround = true;
            currentSpeed = 5f;
        }
       
        else {
            playerOnGround = false;
        }
    }

It didn’t fix my issue, still if I go against a wall the player still jumps super high. I think something else is the problem within the project itself?

Debug it. Print out each frame whether you’re grounded or not. If you’re still grounded in the air, it’s a bug in the code or how your character is set up.

Hey again,
I did what you said. Saw no problems.
But I did something else that acutally fixed it, I just increased th step offset to 1 instead of 0.3. In the CharacterController. :slight_smile: So now the bug is not there anymore. Thanks for your time! :slight_smile: