I’m modifying a controller script from a book. My objective is to use the arrow keys to drive forward/backward and steer/rotate left/right.
The left/right keys rotate properly, but it all occurs too fast. Note the rotateSpeed var, set to 4.0 (which provides for far-too-fast rotation). When I change this to lower values, the left/right rotation becomes a left/right sliding motion instead. I can’t figure out what I’m doing wrong. Can anyone indicate what I can do with this script to control the rate of left/right rotation? Thank you!
var controller:CharacterController;
controller = GetComponent(CharacterController);
var rollSpeed = 6.0;
var gravity = 20.0;
var rotateSpeed = 4.0;
var isControllable:boolean = true;
private var moveDirection = Vector3.zero;
private var grounded:boolean = false;
private var moveHorz = 0.0;
private var rotateDirection = Vector3.zero;
function FixedUpdate() {
if (!isControllable) {
Input.ResetInputAxes();
} else {
if (grounded) {
moveDirection = new Vector3(Input.GetAxis("Horizontal"),0,Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= rollSpeed;
moveHorz = Input.GetAxis("Horizontal");
if (moveHorz > 0) {
rotateDirection = new Vector3(0,1,0);
} else if (moveHorz < 0) {
rotateDirection = new Vector3(0,-1,0);
} else {
rotateDirection = new Vector3(0,0,0);
}
}
moveDirection.y -= gravity * Time.deltaTime;
var flags = controller.Move(moveDirection * Time.deltaTime);
controller.transform.Rotate(rotateDirection * Time.deltaTime, rotateSpeed);
grounded = ((flags & CollisionFlags.CollidedBelow) != 0);
}
}