- Home /
Sprite with non-constant jitter during constant velocity movement.
I know how many people have asked a similar question before, and I've read each one a thousand times, but this one is slightly different and I can't figure out how to fix it, but I know the solution is probably very similar.
I have sprites with rigidbody2D, and a movement script attached, the script just makes them move in the negative y direction forever. Very simple movement.
void Update() {
float rigidVelocity = 100f * Time.deltaTime;
transform.rigidbody2D.velocity = new Vector3 (0, -rigidVelocity, 0);
}
For some reason, every second, it seems to move with jitter, then the next second it's perfectly smooth, then the next second jitter, next second smooth. I have no idea why. Before, I was using a unity sphere and it was perfectly smooth, i switched to sprites and it became jittery, but the 1 second smooth 1 second jitter pattern confuses me. I'm sure it's a super simple fix, but I can't seem to figure it out.
1) You need to do this in FixedUpdate() not Update().
2) You may also want to try using add force rather than directly modifying the velocity, this may not end up being better but it is another method that you can try :
http://docs.unity3d.com/ScriptReference/Rigidbody2D.AddForce.html
http://docs.unity3d.com/ScriptReference/Force$$anonymous$$ode2D.html
3) Check your rigidbody interpolate settings for smoother movement in between FixedUpdate()'s
I've tried all of that and more. I just don't get why it works half the time and then the other half it randomly is jerky, almost like the sprite is going ahead 1 frame and staying behind 1 frame at the same time before eventually settling on the right subsequent frame. It's so baffling.
Do you have Unity Pro? What code are you using at the moment?
No profiler then, which would say what is causing the jitter if it is not this script... Have you done what I said in number 1 above, that is a must do if you have not done it already!!!
Answer by Komak57 · Dec 04, 2014 at 07:59 PM
There are quite a few terms for what "Jitter" defines. Frame spikes can be due to other scripts getting stuck in a long loop trying to process data in the Update() event. Non-frame spikes could be the result of either Floating Point inaccuracies due to rounding (effects you more the farther from Vertor3.Zero you are). Non-frame spikes could also be due to you having more than one collider on an object that in some frames, affects one of the other colliders. It's like the world telling you this object is a Siamese twin, but you're both fighting to stay separate. Additionally, I've found the background profiler in unity will cause spike data on garbage collects, and some background processes and services can generate steady hiccups in games as simple as Minecraft.
Answer by blackmodjo · Feb 10, 2015 at 09:32 PM
Man i had the same issue but i fixed it by going to my prefab that had the sprite and in the rigidbody in the interpolate i used the extrapolate value.
Your answer
Follow this Question
Related Questions
When i make my character animated, he can only move up, down left and right (2D) (JS) 0 Answers
Having Issues Rotating 2d Sprites to face another 2d Object 3 Answers
[2D] Camera movement causes flickering/jittering sprites 2 Answers
Change sprite when moving(2D) 1 Answer
Question on Sprite and Movement 0 Answers