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");
}