Jump + CharacterController EDIT: Solved

Hello! I’m an amateur in this but after spending hours and hours on tutorials and still unable to make any progress I decided to ask help here. I have made multiple character control scripts now and finally found the best fit for my game. However I can’t make the jump work. At the moment this is the jumping part in my script.

public int gravity = 20;
public float jumpForce = 20.0F;
private Vector3 moveDirection = Vector3.zero;

void Update()
{
if (controller.isGrounded) {
//Jumping
if (Input.GetKeyUp (KeyCode.Space))
moveDirection.y = jumpForce;
//transform.Translate ((Vector3.up * jumpForce) * gravity * Time.deltaTime, Space.World);
}

moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}

With this the character jumps, but falls really slowly back to ground. Like it would be moon walking. I also included the old line(the orange one) which I used, but with that character jumped in blink of an eye and fell just as fast. So either of these aren’t working at the moment. I can work with either one, if I just get them to work somehow. I just want really “normal” game jump. Nothing fancy at all.

private CharacterController controller;
    private float verticalVelocity;

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

    private void Update()
    {
        Vector3 inputs = Vector3.zero;

        inputs.x = Input.GetAxis("Horizontal");

        if (controller.isGrounded)
        {
            verticalVelocity = -1;

            if (Input.GetButton("Jump"))
            {
                verticalVelocity = 10;
            }
        }
        else verticalVelocity -= 14.0f * Time.deltaTime;

        inputs.y = verticalVelocity;

        controller.Move(inputs * Time.deltaTime);
    }

I did not try out your code but this is the Code I used for jumping in some of my previous projects, maybe helps you

Hey awesome thank you! I give it a try :slight_smile:
Meanwhile, I figured myself what was the problem in my own code, or at least how to get it work better. Just adding gravity here: controller.Move(moveDirection * gravity * Time.deltaTime);
This made the jump go much smoother. Silly how right in front of me the solution was.