Hi Unity Community! Does anyone have any idea how to make this controller script smooth both in movement and rotation? Does the Move() keep the script unable to be controlled smoothly?
js.
function UpdateMoveDirection(){
var forward : Vector3 = Camera.main.transform.TransformDirection(Vector3.forward);
forward.y = 0;
forward = forward.normalized;
var right : Vector3 = Vector3(forward.z, 0, -forward.x);
var vertical : float = Input.GetAxis("Vertical");
var horizontal : float = Input.GetAxis("Horizontal");
var targetDirection : Vector3 = horizontal * right + vertical * forward;
targetDirection *= moveSpeed;
moveDirection.x = targetDirection.x;
moveDirection.z = targetDirection.z;
if(targetDirection != Vector3.zero){
var rotation = transform.rotation;
rotation.SetLookRotation(new Vector3(moveDirection.x,0,moveDirection.z) * Time.deltaTime);
transform.localRotation = rotation;
}
if(canMove)
controller.Move(moveDirection * Time.deltaTime);
}