I’m improving my jump (as shown in a previous question) and I’d like to make it so the player can still change direction while they’re jumping. Is there a way to implement this using my code (see below)? I also have a character motor attached, if that matters.
void Update()
{
CharacterController controller = GetComponent<CharacterController>();
float rotation = Input.GetAxis("Horizontal");
if(controller.isGrounded)
{
//jumpCount=2; //if on ground, 2 jumps can still be done
moveDirection.Set(rotation, 0, 0); //moveDirection = new Vector3(rotation, 0, 0);
moveDirection = transform.TransformDirection(moveDirection);
if(Input.GetKeyDown(KeyCode.LeftShift) || Input.GetKeyDown(KeyCode.RightShift))
{
running = true;
}
else
{
running = false;
}
if(running)Debug.Log ("yes running");
moveDirection *= running? runningSpeed : walkingSpeed;
if(Input.GetButtonDown("Jump"))
{
moveDirection.y = jumpHeight;
//rigidbody.AddForce(Vector3.up * jumpHeight);
}
}
moveDirection.y -= gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime)
}//end update