flame-engine / forge2d

A Dart port of Box2D
BSD 3-Clause "New" or "Revised" License
181 stars 26 forks source link

camera.followBodyComponent allow to follow center not position #72

Closed mattmyne closed 2 years ago

mattmyne commented 2 years ago

I have a BodyComponent with fixtures that give it a visually off-center center of gravity. When I use camera.followBodyComponent to track it, the view centers on the body's position (the visual center), not its body center.

This means when the body rotates, the world view wobbles around since the body rotates about its center point, not its position point.

I could not find a way to work around this using anchors (since BodyComponent does not have an anchor property) nor any other way of offsetting the tracking point. This is despite the description for followBodyComponent saying "The component is "grabbed" by its anchor (default top left)"?

So to track rotating objects more smoothly, can I suggest camera.followBodyComponent provides a flag to switch between using visual (position) or center of mass (center) values?

mattmyne commented 2 years ago

Apologies; this is a Flame Forge2D issue, not a Forge2D standalone issue. I'll open (and provide a PR) for the Flame Forge2D repository.