I’m working on a kinematic platformer controller, and I’m trying to puzzle my way through some oddities in the physics.
So, I have a moving platform that simply moves up and down on the y axis. It moves by directly setting the rigidbody position in FixedUpdate
rBody.position = (Vector2.Lerp(lerpStart, lerpTarget, AnimCurves.easeInOut.Evaluate(lerpTime)));
Afterwards, the delta is calculated at the end of FixedUpdate
xPosLastFrame = xPosThisFrame;
xPosThisFrame = rBody.position.x;
amountMovedX = xPosThisFrame - xPosLastFrame;
yPosLastFrame = yPosThisFrame;
yPosThisFrame = rBody.position.y;
amountMovedY = yPosThisFrame - yPosLastFrame;
delta = new Vector2(amountMovedX, amountMovedY);
Later, while testing, I decided to calculate the transform’s movement delta in Update
trLastFramePos = trThisFramePos;
trThisFramePos = transform.position;
trDelta = (trThisFramePos - trLastFramePos);
To my surprise, the values are different!
![]()
I placed a print at the start of Update and FixedUpdate, so I can see that they’re both running in sync (there is one FixedUpdate being called for every Update). The platform is set to Kinematic, so it shouldn’t be influenced by any other objects.
Now, I realize these numbers are very close - but they should be identical, shouldn’t they? Is this assumption correct?
Granted, it turned out that my problem wasn’t related to this 0.0001 discrepancy - no surprise there - but I’m wondering if this discrepancy is a natural result of floating point math, or a result of the physics engine’s non-determinism, or if I legitimately ticked a wrong box somewhere and I’m getting unexpected results (this is my main worry).