Hi, I made a simple character controller script here :
var speed : float = 6.0;
var jumpSpeed : float = 8.0;
var gravity : float = 20.0;
var target : Transform;
private var moveDirection : Vector3 = Vector3.right;
function Update() {
var controller : CharacterController = GetComponent(CharacterController);
// I use "target" as a world space reference, will that be a problem?
moveDirection = Vector3.Normalize(new Vector3(Input.GetAxis("Horizontal"), 0f,
Input.GetAxis("Vertical")));
moveDirection *= speed;
// Apply gravity
moveDirection.y -= gravity * Time.deltaTime;
// Move the controller
controller.Move(moveDirection * Time.deltaTime);
transform.LookAt(target.position + moveDirection);
}
It uses the horizontal/Vertical inputs as movement, and rotates to the moving direction. It works well when you use the WASD keys to move around ( the object rotates to the moving direction ), but when you release the directional keys, the object immediately bounces back to (0,0,0) rotation… how do I make the object remain facing that moving direction even when you stopped pressing the buttons? Thanks!