How to add custom 2D physics interactions between two rigidbodies?
What I need
Some way to write a custom 2D physics interactions between two rigidbodies such as a custom Joint2D or an extension to PhysicsServer2D.
I think extending PhysicsServer2D to include a custom function that handles the interaction maybe the way to go (as this seems to be where the joint2D code is) but I'm not really sure how to extend this nor how to make Godot use the extended version.
Most of the resources I have found just say use integrate_forces (not powerful enough for this) or us Physics Servers but they don't say how to use the physics server.
To have two rigidbodies 'tied together' such that when they get to far apart their velocities synchronise preventing them getting further away from each other (as if there was a rope between them).
Solutions that do not apply
- Using many rigid-bodies pin joined together to simulate a rope. This would be a very inefficient solution introducing a lot of new rigidbodies unnecessarily.
- Solutions for KinematicBodies, these do not apply as I am building a physics based game. I may fallback on KinematicBodies but it would require me to rewrite a lot of physics code which I would prefer not to do unless it is my only option.
Solutions I have already tried
- Using a DampenedSpringJoint2D, this join does both compression and stretching forces whereas only stretching forces are needed, the spring also just bounces back instead of synchronising.
- Using a GrooveJoint2D, this does not allow for movement outside of the axis and does not enforce a maximum length properly.
- Custom _integrate_forces on both bodies. This is very close to working, it works if one body is static however, as I cannot access the physics state of both objects the objects cannot be synchronised as each object is working with an outdated information from the other object.