quinton-ashley / p5play

JavaScript game engine that uses q5.js/p5.js for graphics and Box2D for physics.
https://p5play.org
GNU Affero General Public License v3.0
667 stars 184 forks source link

`sprite.addCollider` changes the center of mass/rotation of sprites #312

Closed quinton-ashley closed 7 months ago

quinton-ashley commented 7 months ago

I could've sworn I already fixed this problem lol but yeah... my intention was always to have a sprite's position and the sprite's center of rotation remain the same. Maybe this changed in planck v1 and I didn't notice? idk

quinton-ashley commented 7 months ago

I think there are two ways to solve this:

  1. resetMass would not change the sprite's center of mass

  2. resetMass would change the sprite's center of mass, then keep the sprite in the same location in the world after the collider is added but actually change its position coordinates to reflect the center of mass change.

quinton-ashley commented 7 months ago

ChatGPT says this:

"If you want the center of mass and the body's location to be the same, it would be better to reposition the fixtures relative to the new center of mass while maintaining the same position in the world. This is because changing the center of mass directly can lead to unexpected physics behavior, as it changes the distribution of mass in the body."

Which I agree with, I will try implementing this now.

quinton-ashley commented 7 months ago

Okay problem with that is when adding multiple colliders to a sprite you'd have to take into account its center changing, not backwards compatible or fun!

quinton-ashley commented 7 months ago

fixed in v3.20.1, see release changelog