Simple, Non-Glitch Jump Script

I’ve been looking at tons of posts on C# Jump Scripts, but they are all glitchy and don’t seem to work that well - for example, you can spam the “Space” bar to fly up (with GetKey AND GetKeyDown).


All I want is a simple jump script that is non glitchable that you could therefore use for a game like this -

The jump height and speed is the same every time, regardless of the amount of time the screen is pressed.

Super simple, but I haven’t found ANYTHING on the forums on how to do this.

Thanks!

Try this:

    public float JumpSpeed = 8.0F;
    public float Gravity = 20.0F;

    private Vector3 _Move = Vector3.zero;
    private CharacterController _Controller;

    private void Start()
    {
        _Controller = GetComponent<CharacterController>();
    }

    void Update()
    {

        if (_Controller.isGrounded)
        {
            _Move = Vector3.zero;

            if (Input.GetButton("Jump"))
                _Move.y = JumpSpeed;

        }
        else if ((_Controller.collisionFlags & CollisionFlags.Above) != 0)
            _Move.y = 0;
        else if ((_Controller.collisionFlags & CollisionFlags.Sides) != 0)
            Debug.Log("You Lose");

            _Move.y -= Gravity * Time.deltaTime;
        _Controller.Move(_Move * Time.deltaTime);
    }

That worked great, thanks so much!