- Home /
whats wrong with this script
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)
There is nothing wrong with code, it's almost the same as what's available in the unity's scripting reference. Can you tell what exactly is the problem? Do you get an error? No error but it won't move?
The "Hoizontal" typing mistake should give you errors or warnings... $$anonymous$$aybe you named the axis that way in the input manager but i guess it should be Horizontal
Answer by Bunny83 · Apr 19, 2011 at 03:02 PM
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".
Your answer
![](https://koobas.hobune.stream/wayback/20220613123758im_/https://answers.unity.com/themes/thub/images/avi.jpg)