Character not jumping smoothly using CharacterController
Hello
I am trying to program simple character movement. My character isn't jumping properly. What I mean is : the sphere that represents said character simply teleports up and falls at a constant speed instead of moving up, then smoothly falling down.
Here is the actual code of the said character core :
public CharacterController controller;
private float direction;
private Vector3 moveDirection = Vector3.zero;
private static float BASE_SPEED;
private static float BASE_JUMP;
private static float BASE_GRAVITY;
// Use this for initialization
void Start () {
if (gameObject.GetComponent<CharacterController>() != null)
{
controller = GetComponent<CharacterController>();
}
else
{
gameObject.AddComponent<CharacterController>();
controller = GetComponent<CharacterController>();
};
BASE_SPEED = 8;
BASE_JUMP = 100;
BASE_GRAVITY = 20;
direction = 0;
}
// Update is called once per frame
void Update () {
controller.enabled = true;
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= BASE_SPEED;
if ((Input.GetButton("Jump") || Input.GetKey(KeyCode.Space)) && controller.isGrounded){
moveDirection.y = BASE_JUMP;
}
moveDirection.y -= BASE_GRAVITY * Time.fixedDeltaTime;
controller.Move(moveDirection * Time.fixedDeltaTime);
}
Does anyone know what the problem seems to be?
Thank you.
Comment