var CurrentPosition = RigidBody.transform.position;
Physics.Simulate(0.02f);
RigidBody.transform.position = CurrentPosition;
This piece of code runs every few seconds in Update(). It’s just a small portion of a bigger project I’m working on, but it causes the player to jitter, whenever it runs. Why exactly does this happen and how would I fix it?
What are you trying to achieve, obviously you are adding some strange additional simulation step.
Physics is running by itself anyway no need to simulate it inside Update. (depends on what you are doing).
As I said, smaller piece of a much larger project. That was a dumb example for me to give.
When doing clientside reconciliation inside unity, would I just be better off doing the whole re-simulation in another scene? I’ve tried like 20 different ways to rewind and re-simulate to correct the physics from the server value, but it’s extremely jittery with whatever I try.
I feel like the only way to do this is just inside a different scene running it’s own physics?
Yeah that was a dumb example for me to give. Check out the reply I gave to Kurt and let me know what you think about doing that in a different scene. More input the better
The reason it’s jittery is because Update (and your game) does not run at a consistent framerate. Therefore, you are now simulating Unity’s fixed-timestep physics at a non-fixed time interval.
I tried it in fixedupdate and lateupdate, it did not help.
I even tried doing it without a network, and just taking the last 5 predicted movements from my array, teleporting my character back to the first of the 5 values, and re-simulating all of the 5 movements. The rigidbody jittered whenever I did this.
if (PerformSimulation == true)
{
RigidBody.position = (PastNetworkingStuffClass.NetworkingPlayerPosition[PastNetworkingStuffClass.NetworkingPlayerPosition.Count - 5]);
for (int i = PastNetworkingStuffClass.NetworkingPlayerPosition.Count - 5; i < PastNetworkingStuffClass.NetworkingPlayerPosition.Count; i++)
{
RigidBody.velocity = PastNetworkingStuffClass.NetworkingPlayerVelocity[i] * Speed;
Physics.Simulate(0.02f);
}
PerformSimulation = false;
}
Here is an experiment I made. It does NOT use networking, and just grabs the past predicted inputs, and re-simulates them, so we don’t have to worry about any networking variables going wrong for this experiment. Whenever this is called, there is a very clear jitter. This is in update() by the way.
I then had another idea, to only simulate an invisible rigidbody with no camera attached to it, and then have the real player lerp to the invisible rigidbody’s position, and I did something like this:
if (PerformSimulation == true)
{
RigidBody.isKinematic = true;
for (int i = PastNetworkingStuffClass.NetworkingPlayerPosition.Count - 5; i < PastNetworkingStuffClass.NetworkingPlayerPosition.Count; i++)
{
Physics.Simulate(0.02f);
}
RigidBody.isKinematic = false;
PerformSimulation = false;
}
(also in update), and this produces the same jitter. All I’m trying to do is reconciliate/“re-simulate” my player’s movements all during a single frame. If I remove physics.simulate, it does not jitter. So we can conclude that physics.simulate is causing the jitter, I just don’t know why. Any help is appreciated.