Advanced Player Movement - Move while Jumping?

Advanced Player Movement - Move while Jumping?


Hi, I want to make a basic Vehicle Movement system… but I can’t figure out to allow the player to move while jumping in the air? Here is what I’m working with.

Also wanted to add inertia/momentum, but that seems to be too advanced for me right now.

Thanks in advance to anyone who helps!!


     CharacterController controller = GetComponent<CharacterController>();

        if (controller.isGrounded) 
		{
            moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
            moveDirection = transform.TransformDirection(moveDirection);
            moveDirection *= speed;

	// turn right or left with Joystick (Deadzone of 20%)
            if (Input.GetAxis("Horizontal") > 0.2)
            {
                transform.Rotate(0, 5, 0);
            }

           if (Input.GetAxis("Horizontal") < -0.2)
           {
             transform.Rotate(0, -5, 0);
            }

            if (Input.GetButton("Jump"))
                moveDirection.y = jumpSpeed;
        }


        moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(moveDirection * Time.deltaTime);
	
		if (hp == 0)
		{
			Application.LoadLevel ("Menu");
		}

This is old and you probably have fixed the problem.


Move your moveDirection assignment **outisde** the isGrounded statement.

Then, pass it your gravity value for the Y axis, and only multiply your speed by the X and Z axes (since Y is gravity, and multiply it by speed may be not desired).

I can show you how: