I’m trying to have my character be able to move even if airborne. But when I jump, he only goes up about 0.08 - 0.1 units. Then when he falls back down, it’s as if he is in slow motion, even though I set the gravity to 20. My code is below.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
public float Speed = 6.0f;
public float JumpSpeed = 8.0f;
public float Gravity = 20.0f;
private Vector3 moveDirection = Vector3.zero;
// Update is called once per frame
void Update () {
CharacterController controller = GetComponent<CharacterController>();
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= Speed;
if (Input.GetButton("Jump") && controller.isGrounded){
moveDirection.y = JumpSpeed;
}
moveDirection.y -= Gravity * Time.deltaTime;
controller.Move(moveDirection * Time.deltaTime);
}
}