Problem
Currently we only do the localToWorld update once per frame, however, when the game is below 30 fps, we run the systems tagged with the fixed step multiple times in one frame. This is particularly troublesome since the Collisions need the updated localToWorld to compute if objects are colliding and their contact points.
With the game the game itself also running at a higher frame rate, the movement with physics looks very "low fps", due to the position only being updated at 30 fps.
Proposed solution at the moment
Put Position, Rotation, etc in a single Transform component, to make sure the matrix is always updated.
Ideally we'd have a Transform, a GlobalTransform, and a FixedTransform.
FixedTransform would hold new transform resulting from the fixed update. The AccumulatedCorrection would still hold the correction of the position to apply to FixedTransform. This means the physics would not directly manipulate the Transform but instead the FixedTransform.
The Transform would be updated by interpolating the FixedTransform between fixed updates. (see: https://docs.rs/avian2d/latest/avian2d/interpolation/struct.PhysicsInterpolationPlugin.html)
- Note: When we do the fixed update, we need to always have exactly the
FixedTransform applied to the Transform. (so when performing 2 fixed updates in one frame, when doing the second we need to make sure the first is instantly fully applied to the Transform)
Problem
Currently we only do the localToWorld update once per frame, however, when the game is below 30 fps, we run the systems tagged with the fixed step multiple times in one frame. This is particularly troublesome since the Collisions need the updated localToWorld to compute if objects are colliding and their contact points.
With the game the game itself also running at a higher frame rate, the movement with physics looks very "low fps", due to the position only being updated at 30 fps.
Proposed solution at the moment
Put
Position,Rotation, etc in a singleTransformcomponent, to make sure the matrix is always updated.Ideally we'd have a
Transform, aGlobalTransform, and aFixedTransform.FixedTransformwould hold new transform resulting from the fixed update. TheAccumulatedCorrectionwould still hold the correction of the position to apply toFixedTransform. This means the physics would not directly manipulate theTransformbut instead theFixedTransform.The
Transformwould be updated by interpolating theFixedTransformbetween fixed updates. (see: https://docs.rs/avian2d/latest/avian2d/interpolation/struct.PhysicsInterpolationPlugin.html)FixedTransformapplied to theTransform. (so when performing 2 fixed updates in one frame, when doing the second we need to make sure the first is instantly fully applied to theTransform)