system
April 19, 2011, 12:22pm
1
my script is for moving around litteraly plz tell me whats wrong with it
var speed = 3.0;
var rotateSpeed = 3.0;
function Update ()
{
var controller : CharacterController = GetComponent(CharacterController);
//Rotate around y - axis
transform.Rotate(0, Input.GetAxis ("Hoizontal") * rotateSpeed, 0);
// Move forward / backward
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
}
@script RequiresComponent(CharacterController)
Well, like Kourosh said there's nothing really wrong except that you don't use Time.deltaTime to compensate the framerate and to make the movement/rotation time based instead of frame based.
Change those two lines:
transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed * Time.deltaTime, 0);
and
controller.SimpleMove(forward * curSpeed * Time.deltaTime);
You will have to adjust the rotation speed to match your needs. It will be in degrees/sec. The movement speed is in units/sec.
edit
I've just found a typing mistake: the axis is named "Horizontal" by default not "Hoizontal".