- Home /
Stuttering in simple 2D game using interpolation?
Basically all my movement is stuttering in a very simple 2D game (also if I build the game). It looks as if I have an average framerate of ~10 FPS even though profiler says I have ~1000 FPS.
I do everything according to the "book": everything that is moving is using a 2D rigidbody with interpolation. I only move objects by changing movement speed (and never move/translate game objects directly). The camera update is in LateUpdate. I've turned vsync both off and on without any improvement.
What is even weirder is that this behaviour seems to come at random times. Sometimes when I run the game I have no stutter (like ~1/10 times).
I have a feeling there is something wrong with the interpolation used in Unity.
Help!
So you're moving with rigidbody? Are you changing rigidbody.velocity
? I've noticed that it causes a jumping effect, but certainly not making it look like 10fps.
Try adding a simple script with this in the update, place it on a cube, and see if it looks like it's 10fps:
void Update() {
transform.position += new Vector3(Vector3.left * Time.deltaTime, 0f, 0f);
}
If you put this on an object in game, does it look like it's stuttering?
I feel like the problem is simply the LateUpdate rate. It's called every 0.2 seconds defaultly, so you may want to look on how to change physics update rate, and make it more like 0.1 or 0.05. It's less efficient and performance heavy, though
Hey! Thank you for the answer. Gave a thumbs up for trying to help! :-)
I'm moving objects with a rigidbody using only rigidbody.velocity. I have constant 200 FPS and still get stuttering; even when I build the game! I'm starting to think that there might be an issue with the interpolation that Unity is using.
I'll try just moving objects directly ins$$anonymous$$d and see what happens!
LateUpdate called every 0.2 seconds by default? That sounds really weird. Are you sure about that? I feel like the camera is not really stuttering... more as if the rigidbodies are stuttering.
Pretty sure that Firedan1176 mixed up FixedUpdate with LateUpdate because LateUpdate is stated to be frame dependent (like Update) in the documentation.
http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.LateUpdate.html
http://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.FixedUpdate.html
Thank you for answer. I gave you a thumbs up for helping.
maccabbe I think so too! I have tried changing my FixedUpdate rate but with no success. Also tried different values of $$anonymous$$aximumFixedTimeStep!
Answer by DimitriUK · Jul 11, 2015 at 10:34 PM
It sounds like you need your camera to follow in an FixedUpdate() function, check to see if your camera follow script is Update(), if so, change that now and it should work.
Good luck with your project.
As mentioned above the problem exists even if the camera is stationary! $$anonymous$$oving the camera follow to FixedUpdate() will also create other problems. The camera following should be in LateUpdate().
Apologies, I never read the comments above. I was answering from my experience with laggy objects such as Rigidbodys, etc. I just remember I did FixedUpdate and changed the Rigidbody's interpolation to one of the two and it finally worked.
If neither of that works, I'm really sorry, I can not help.
Your answer
Follow this Question
Related Questions
so I'm trying to make a 2D platform but the first animation i make is the only one that registers 0 Answers
[Solved] Does Unity's 2D Tilemap Editor 1.0.0 Include Rule Tiles? 1 Answer
Having some stuck issues on the 2D infinite runner 0 Answers
When 2D Car Turns Upside Down, Game Over Scene Should appear. 1 Answer