I’m trying to make 2D physics for game where world is looped on screen sides. If part of any body (static, rigid, character) moves over screen edge - it should appear on the opposite edge and affects physics of bodies nearby as expected.
Visual wrapping is easy but physics is a big problem - I couldn’t find any way to make 2 bodies to act as one. Just duplicating collision shapes didn’t work - it changes body reaction to rotation. I also tried to copy back and forth linear_velocity and angular_velocity in _integrate_forces callback - it somehow works, but bodies jitters violently.
Can I make such behavior without modifying physics engine?
For context: some objects in game expected to be big, and might self-collide. Also in some scenes many objects may fill full screen width and should stay stable.
After some research of source code I come to conclusion it is impossible without engine modification.
And most appropriate way to modify is introducing new kind of joint (like pin joint but with individual pivots for bodies A and B).
I think if you’re clever about the transition zone, you can fake it by pointing the visual copies to the physics on the other side and just changing the translation.
When the object moves across the transition zone you need to copy the rigid body object and its properties and maybe you need to keep more than one copy for a couple of frames and interpolate the differences to make it smooth.
But I think that should do the trick.
in other words there needs to be somewhere a break along the looping axis, where you need to integrate things and yeah that could be done with a custom joint type.