Update: I think this might be a webplayer issue, because in standalone it works at normal speeds. In fact it seems to only happen in some machines. I had a friend test it and in his webplayer ran ok and the deltaTime and fps where the same as mine… Is my webplayer possessed? Tried reinstalling it to no avail.
Hi, I want to make some framerate independent movement code using 2D physics for a rotating sprite, but I think I might be missing something because when I test it in the web player it runs a lot faster than in the editor.
This is the code:
function FixedUpdate(){
rigidbody2D.AddForce(new Vector2(moveHorizontal*100*Time.deltaTime,0));
rigidbody2D.AddTorque(-moveHorizontal*100*Time.deltaTime);
}
function Update(){
if(Input.GetKey(KeyCode.LeftArrow)){
moveHorizontal = -1;
} else if(Input.GetKey(KeyCode.RightArrow)){
moveHorizontal = 1;
} else {
moveHorizontal = 0;
}
}
The GameObject the code is attached to, has a polygon collider and a rigidbody2D which has a mass of 0.7 and no drag. In the editor (and also on an Android device) works at the same speed, but in the web player it moves a lot faster.
I thought using Time.deltaTime or even fixedDeltaTime (which I tried too with the same result) would make it framerate independent. What can be the cause of it behaving so differently?
Thank you.