- Home /
RigidBody2D Movement Stuttering
I'll get this out of the way - I've tried:
Velocity
AddForce
update * deltatime/smoothdeltatime
fixedupdate - changed timestep from 0.2 to 0.01666667 to 0.01, etc
moveposition
interpolation
extrapolation
etc
The problem I'm having is that I need to move a rigidbody2D object without it micro-stuttering. I generally run 750+ fps when I build, but that doesn't matter much when even with vsync or limiting the framerate to 60 or 120 doesn't change the behaviour.
I noticed my main player would "vibrate" as he moved along the X axis (I control jumps with AddForce just fine). But applying any kind of physics to the X axis causes him to vibrate. He has NO drag, has a physics material that sets drag to 0 (so I can control all accel and decel on my own). No amount of fiddling with timings, speeds, acceleration, straight setting the velocity, etc will alleviate his micro stuttering. I've tried setting the framerate equal to the timestep and vice versa to try to eliminate pretty much everything i can think of.
I first noticed the rigidbody2D micro stutter when my entire scene would "stutter" since the camera snaps to the player's X axis to follow (in LateUpdate) which caused my parallax which moves based on the camera's position to also stutter.
I unlocked my Camera from the player's X coordinates and now move the camera using Translate and dampen the X ever so slightly to prevent the camera movement from being choppy due to the main player vibrating. I do this by simply getting the distance from the camera's X and the player's X and using a multiplier on that number, use that as my "speed", +-, based on position with a lerp between previous frame and current frame to prevent any stuttering at max speed. It's now smooth as silk no matter what framerate the game plays at, vsync or not - silky smooth.
This is when I saw my main rigidbody2D micro stuttering. Because the environment moved so smoothly and the camera was well controlled, I can now see my player vibrating, stuttering, skipping - which was the entire scene (except the player locked in the center of the screen with my previous camera movement).
I am at a loss. I've been looking for about 2 days through this forum and other avenues to see if I can fix my issues. 99% of the time it's due to misunderstanding a fixed time step, fixed update, framerate, etc. What is odd is that I have a few other rigidbody2D's that move just fine on their own without stuttering.
I also checked to be sure there was no variance of maximum speed by printing velocity of every frame - which is a lot to go through at 1k+ in the editor and 750+ in a build. Every frame, every fixedUpdate, always the same.
I'm pretty clueless, at this point. Help, anyone?
WHat have you dont to fix this, please tell us! Help us out here!
Answer by mactinite77 · Feb 04, 2015 at 07:12 AM
Jsip,
I was running into this problem tonight. I was able to solve(?) it by doing everything in Update, and then changing the fixed timestep to 0.001. I'm not sure how this will perform with a lot of physics objects, but that's what stopped the micro-stuttering to be visible to me.
It doesn't seem like much of a solution, but it was the only way I could do it without ditching Rigidbody2D.
Hey mactinite, what do you mean by fixed timestep? I have this exact issue and nothing so far has fixed it. Your reply is different than all others so I wouldn't $$anonymous$$d seeing if yours fixes it.
If I'm remembering correctly there is an option under Edit>Project Settings>Time for fixed timestep.
Answer by jsip · Feb 04, 2015 at 06:45 PM
Thanks mactinite77, I have decided to use Translate instead and roll my own physics.
The problem I am seeing with micro-stuttering is phase shifting between physics updates and framerate. So I create my own math and apply that with translate. Super smooth no matter the fixed timestep.
Mods can close this.
Do you $$anonymous$$d sharing what you did? I've tried for weeks to fix this, but am unable to.
Your answer
Follow this Question
Related Questions
RigidBody immediately stops after AddForce 1 Answer
Unity Physics On Input Issue? 0 Answers
Strange Rigidbody Behavior 0 Answers
Collisions causing Rigidbody to go Haywire and move randomly. 1 Answer
Ground clamping a rigidbody on slope 1 Answer