- Home /
Rigidbody jitters during movement
I've been trying to fix this for days and it's driving me crazy. I'm trying to build a clone of this game:
The concept is simple. There are platforms moving upwards and the player's job is to control the ball and keep it on the platforms. If the ball the ball hits the spiky platform or the spikes at the top and the bottom, the player loses a life.
However, I'm struggling with moving the platforms. The platform that I've created has RigidBody attached and I'm using the function rb.MovePosition(transform.position + transform.up * Time.fixedDeltaTime);
in the platform's FixedUpdate() function. The RigidBody component of the platform is set to "interpolate" and "isKinematic" is set to true.
In the earlier versions of this game (which I released for Android and then deleted a year later), the movement of the platform was perfect. The platform smoothly moved from the bottom the screen to the top without any shakyness or jitteriness. However, in the version that I'm working in now, the platforms are pretty jittery in movement.
I originally thought it was because I added a lot more game objects and scripts to my game and made it too complex. So I created a new project and moved the platforms there. Unfortunately, the jitteriness didn't go away.
I've tried all kinds of codes for the platform's movement. I've tried using Mathf.MoveTowards, Transform.Translate, Vector3.MoveTowards but nothing is working (I had to change the FixedUpdate to Update because these aren't using physics properties).
What's going on? Why did my platforms move so smoothly in the previous versions of my game but not in the current work-in-progress version of my game? I know that I used an older version of Unity for the old versions of the game. Could it have anything to do with this?
Another thing you should know is that in the previous versions of the game, I never set the frame rate to a specific value. But it didn't matter because the game ran very smoothly. In this version, I tried setting frame rate to 60 but it was no use. The platforms are still shaking as they moves upwards.
I even played around with the Fixed Timestep. Didn't work.
I don't recognize some issue in your observations, so maybe in this case you should wrap up a zip of the project, post it so some of us could unzip a copy and try it out.
That said, I do think that transform.forward * Time.fixedDeltaTime is not actually a rate. What is the scale of the artwork? This would tend to cause speed to be bound to the fixed frame rate, and I recall that fixedDeltaTime isn't tracking time like deltaTime. Documentation, somewhere I don't recall, states that we should use deltaTime and not fixedDeltaTime, even in fixed update functions. I think, without being certain, that fixedDeltaTime isn't what it seems to be, and might even have changed definition over time.
What I think is better is to consider a rate per second based on the units of your artwork, scale "forward" to that rate, then multiply by deltaTime - but I have no idea of this is central to your problem, which is why I'm not posting this as an answer.
Sorry for the late reply. What exactly do you mean by "scale" of the artwork? It's not something I'm familiar with. Also, if I wanted to create platforms which continuously move across the screen during gameplay, then what would you recommend? Update or FixedUpdate? Because I might have read somewhere that FixedUpdate is only suitable for player characters and not spawned characters like platforms in this case.
Does anyone have any comments on this issue? I'm suspecting that it has something to do with the newer versions of Unity. I created a new project and re-created my game from scratch. The only difference is that in this project, I didn't include any of the enhancements that I added after first releasing my game. So in other words, I brought my game back to the state where it didn't jitter on Android. I used all the old scripts that the old version of the game had. And guess what, it was still lagging. So I'm guessing that it has something to do with the new 2018 version of Unity that I'm using. Back when I released this game (the non-jittery version), I was most like using Unity 4.8.
Hey! I started following your question, because I was interested what is the solution, because based on the description you are using the physics well. I was only puzzled why the platforms aren't set to kinematic. Now that you updated the question (thanks!), I have a suggestion: you could try moving the platform directly with rigidbody.position
, as kinematic rigidbodies don't need to care about collisions that much. I'm not sure this will work, but maybe it will.
Answer by Sanjay112000 · Feb 14, 2021 at 12:39 AM
I solved it by setting rigidbody interpolation to none
Answer by BlueDarterz · Jul 31, 2018 at 02:37 PM
I was having a similar issue in my 3d project. Ultimately after trying many things I found it was fixed after ticking "Is Kinematic." It has yet, as fair as I can tell, interrupted any plans or ideas ive implemented. Maybe give it a shot?
I apologize. I made a mistake in the description. I actually had iskinematic set to true this whole time. I edited the description.
But it doesn't matter. The platforms still jitter.
Your answer
Follow this Question
Related Questions
Character Controller Jittering 0 Answers
Rigidbody interpolation conflicts with transform.position 0 Answers
C#: Why does this strange jittering occur?? 0 Answers
Player movement jittery when hitting walls and using Rigidbody.MovePosition. 1 Answer
Rigidbody character clips through or jitters on corners. 1 Answer