When my character controller turns 90 degrees, the rotation happens while the character is moving and it looks really smooth. However, when I turn the character 180 degrees (ie. Pressing up and then pressing down) the controller literally “teleports” a couple units. For example, pressing up for awhile and then pressing down will make the character jump down a unit or two. This teleportation also happens when a directional key is released and than another is pressed - regardless of angle.
Is there a way to fix this? Here’s the code I’m using:
using UnityEngine;
using System.Collections;
public class LukaCController : MonoBehaviour {
float speed = 15.0f;
float gravity = 40.0f;
bool isMoving;
Vector3 moveDirection = Vector3.zero;
Quaternion originalRotation;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
CharacterController controller = GetComponent(typeof(CharacterController)) as CharacterController;
if (controller.isGrounded)
{
moveDirection = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
moveDirection = moveDirection * speed;
if (moveDirection != Vector3.zero)
{
transform.rotation = Quaternion.LookRotation(moveDirection.normalized);
}
}
//Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
//move the controller
controller.Move(moveDirection * Time.deltaTime);
}
}