I'm developing a 2.5D mobile game with Unity. In order to move the character back and forward I'm using a piece of code inside the update function:
void Update () {
if (shouldMove==true){
transform.Translate(Vector3.forward * 3 * Time.deltaTime);
}
}
So that code works pretty well when the game is running at 60 fps, but when the fps go down to 30 or less, the character starts to vibrate while moving. I've tried to test the same code with a plane terrain and it worked well, so maybe the problem is the collision between the character's and the terrain's colliders. However, I don't understand why if the fps are high it works well. I've tried both capsule collider and a mesh collider but no one has worked. What do you think? Should I try to use another code?
Edit 1: I'm using a capsule collider and a rigidbody. Should I use a Character Controller?
shouldMove
boolean is being continually flipped on and off thus the character only moves on certain frames and that the way you interface with the physics engine is what drives theshouldMove
value? – Chris Sinclair