Hi everyone!
I’m working on a very simple 2D game for android, the game only have a ground and a ball which moves at constant speed on X axis and nothing else.
The ground has a collider and the ball has a Rigidbody2D, a collider and this simple script to move it at constant velocity:
**
using UnityEngine;
using System.Collections;
public class PlayerController : MonoBehaviour {
public float running = 10f;
void Update() {
rigidbody2D.velocity = new Vector2(running, rigidbody2D.velocity.y);
}
}
**
When I play the game on my tablet or any other mobile device and the ball moves at constant speed you can see every 2-3 seconds a little stuttering. The stuttering occur just on the object which the script of movement are applied, in this case, the ball.
Is not a type of stuttering of Interpolate/Extrapolate or Update/FixedUpdate, this stuttering looks different.
I have tried almost everything what I have seen on google searches but none have solved my problem.
I have tried too delete the rigidbody at the ball and move it with differents scripts, but the stuttering still there. Looks like the problem is something related with the movement engine.
Can somebody help me with this problem please?
I’m trying to find a solution to this problem more than a year, this is very frustating!
I appreciate any help you can give me.
Thanks!
I’ve had this problem on Android before, and it was down to the number of fixed updates per frame fluctuating. You can verify this by using this test code:
int FixedUpdatesPerFrame = 0;
void FixedUpdate()
{
FixedUpdatesPerFrame++;
}
void Update()
{
Debug.Log( "FixedUpdatesPerFrame: " + FixedUpdatesPerFrame );
FixedUpdatesPerFrame = 0;
}
If you have your time step parameters set to something sensible like: Fixed timestep = 0.016666 Maximum timestep = 0.0166666 then you should see this:
FixedUpdatesPerFrame: 1
If you see a fluctuation in that value at the same time as the stuttering then you’ve found your problem. I’m guessing it’s down to either a bug in Unitys time management, or maybe the Android timer isn’t very precise.
I solved it by reducing the Fixed timestep a bit. A better solution for a simple case like this would be to remove the rigid body and just move it inside Update() by modifying transform.position.
I know this thread is 2 years old, but I’m not sure the question has been answered fully. By default, Unity runs all it’s games in a fullscreen windowed mode. This prevents the engine from having control over the refresh rate of the monitor. Try going into the player settings and set the fullscreen mode to “exclusive mode”. I made a video compiling all the fixes to stuttering that I know of. I hope this helps someone.
1
I’m having a similar issues im making a zombie/survival tps and when I fire the animations are jerky. Only when I fire. Top half of body jerks. I can’t seem to fix it.