- Home /
Object is stuttering on rotation
Heres the thing, I have written a code in javascript that will make my player rotate, the problem is when I walk around an object ( such as a tree ) the object that I am walking around appears to be stuttering in both the unity player and in the final .exe. Is this a problem with my code or is it a hardware problem?
Here is the code that I am using for my player movement:
#pragma strict
var power : float = 20.0;
function Update () {
if(Input.GetKey("w")){
rigidbody.AddRelativeForce (0, 0, power);
}
if(Input.GetKey("s")){
rigidbody.AddRelativeForce (0, 0, -power);
}
if(Input.GetKey("a")){
transform.Rotate (0, -180 * Time.deltaTime ,0);
}
if(Input.GetKey("d")){
transform.Rotate (0, 180 * Time.deltaTime ,0);
}
}
Thanks in advance.
Comment
This code won't work right since it's framerate-dependent for the "w" and "s" keys. Adding forces like that should be done in FixedUpdate. Also it would be better if you didn't hard-code the keys, but used GetAxis ins$$anonymous$$d.