Skip to content

feat: add BodyTypeManual and body flags to physics2d rigidbody#882

Open
AnthonyWadham wants to merge 1 commit intoAnthony/physics2d-componentsfrom
Anthony/fix-component-updates-post-step
Open

feat: add BodyTypeManual and body flags to physics2d rigidbody#882
AnthonyWadham wants to merge 1 commit intoAnthony/physics2d-componentsfrom
Anthony/fix-component-updates-post-step

Conversation

@AnthonyWadham
Copy link
Copy Markdown
Contributor

@AnthonyWadham AnthonyWadham commented Apr 2, 2026

TL;DR

Added a new BodyTypeManual rigidbody type for gameplay-driven entities that use Box2D only for collision detection while maintaining full ECS control over position and velocity.

What changed?

  • Added BodyTypeManual constant to the rigidbody component with detailed documentation explaining its behavior
  • Extended Rigidbody2D struct with new body flags: Active, Awake, SleepingAllowed, Bullet, and FixedRotation
  • Added NewRigidbody2D constructor function that sets Box2D-compatible defaults
  • Implemented custom UnmarshalJSON method to handle backward compatibility with old snapshots while applying proper defaults
  • Modified body creation to set zero velocity in Box2D for manual bodies since ECS owns their velocity
  • Updated reconciliation logic to always enforce zero velocity in Box2D for manual bodies and apply all new body flags
  • Created new writeback system (WritebackPhysicsSystem) that runs on PostUpdate hook to sync Box2D simulation results back to ECS components
  • Added writeback logic that skips static and manual bodies, only updating dynamic and kinematic body positions/velocities from Box2D
  • Updated validation to accept the new BodyTypeManual type
  • Added Body function to expose underlying Box2D body for read-only queries
  • Exported the new body type constant in the plugin interface

How to test?

Added up stack into the integration tests

Why make this change?

This enables better separation of concerns for gameplay-driven entities like player characters, NPCs, and AI-controlled objects. These entities can use their own movement logic (input handling, pathfinding, AI) while still benefiting from Box2D's collision detection capabilities. The manual body type prevents Box2D from overriding gameplay-computed positions while maintaining collision interactions with physics-simulated objects. The additional body flags provide fine-grained control over Box2D simulation behavior, matching the full feature set of the underlying physics engine.

Copy link
Copy Markdown
Contributor Author

AnthonyWadham commented Apr 2, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more


How to use the Graphite Merge Queue

Add the label graphite/merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@AnthonyWadham AnthonyWadham changed the title feat: writeback component update feat: add BodyTypeManual and post-step writeback system Apr 2, 2026
@AnthonyWadham AnthonyWadham marked this pull request as ready for review April 2, 2026 15:09
@AnthonyWadham AnthonyWadham force-pushed the Anthony/fix-component-updates-post-step branch from c66bed2 to 6bf8afb Compare April 2, 2026 18:31
@AnthonyWadham AnthonyWadham changed the title feat: add BodyTypeManual and post-step writeback system feat: add BodyTypeManual and body flags to physics2d rigidbody Apr 2, 2026
@AnthonyWadham AnthonyWadham requested a review from rmrt1n April 2, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant