Skip to content

Fix localToWorld update and smooth physics movement. #1459

Description

@fallenatlas

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)

Metadata

Metadata

Assignees

Labels

B-CollisionsB-PhysicsB-TransformP-UrgentThis issue is a big priority, and it would be good to close it ASAPS-TriageIssues whose priority still has to be figured out

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions