Glitchy movement

Hello, I am making a simple FPS game and I have a little problem with movement.

Whenever I am walking into wall and jump, player won’t jump and starts twitching like he wants to jump but is stopped by the wall. I tried Physics.CheckBox but it doesn’t solve my problem because it just restrict player from jumping when near the wall

Here’s my code:

public CharacterController cc;
    public float speed = 100f;
    public float jumpHeight;
    public float gravity = -9.81f;

    public Transform groundCheck, collideCheck;
    public float groundDistance = 0.4f;
    public LayerMask groundMask;

    public bool isGrounded;
    public bool isColliding;
    public bool isAbleToJump = true;
    Vector3 velocity;
    public float moveSpeed;
    public Camera cam;

    void Update()
    {
        isGrounded = Physics.CheckSphere(groundCheck.position, groundDistance, groundMask);
       // isColliding = Physics.CheckBox(collideCheck.position, new Vector3(0.55f, 0.5f, 0.55f), Quaternion.identity, LayerMask.GetMask("Wall"));

        if(isGrounded && velocity.y < 0)
        {
            velocity.y = -2f;
        }

        float movX = Input.GetAxisRaw("Horizontal");
        float movZ = Input.GetAxisRaw("Vertical");

        movX = isGrounded ? movX : movX / 3;
        Vector3 move = transform.right * movX + transform.forward * movZ;
        moveSpeed = Input.GetKey(KeyCode.LeftShift) ? speed * 2 : speed;
        if (movX == 1 || movZ == 1)cam.fieldOfView = Input.GetKey(KeyCode.LeftShift) ? cam.fieldOfView + Time.deltaTime*25 : cam.fieldOfView - Time.deltaTime * 25;
        if (cam.fieldOfView >= 80) cam.fieldOfView = 80;
        if (cam.fieldOfView <= 70) cam.fieldOfView = 70;
        cc.Move(move * moveSpeed * Time.deltaTime);

        if (Input.GetButton("Jump") && isGrounded && isAbleToJump && !isColliding)
        {
            velocity.y = Mathf.Sqrt(jumpHeight * -2f * gravity);
        }
        velocity.y = velocity.y < -100f ? -100 : velocity.y + gravity * Time.deltaTime;
        cc.Move(velocity * Time.deltaTime);
    }

Also if there’s any better way to make movement, I am open to changes. I tried Rigidbody movement but I got stuck when I wanted a player to jump because AddForce overwhelmed me.
Thank you for any advice

I wrote about this before: the Unity example code in the API no longer jumps reliably, apparently because it calls .Move() twice per frame. I have reported it. Here is a work-around:

The code above is for a third person controller but the point remains the same about not calling .Move() twice per frame.

Also there are lots of other full up FPS controllers out there on the wiki:

http://wiki.unity3d.com/index.php/Scripts/Controllers

1 Like

Experimenting with writing my own FPS controller, I’ve been having good results just firing a ray straight down as far as the grounded check.

I’ve also seen solutions which check whether there is any downward velocity. Haven’t tried it though, but might be problematic while going down a hill.