Body A colliding with Body B to make Body A move to x, y

I’m pretty new to Solar2D and its physics, and I want something to happen like this:

Body A drops down, collides with Body B (a static platform) and then Body A goes to the contentcenterX and Y.

How would I go about this?

Thanks in advance!

Looking into the solar2d documentation on collision handling will be the starting point for this. You basically first want to identify the moment when the collision is detected— I’d suggest implementing a collision listener and then putting a simple print statement there which outputs to console when the two bodies collide

Once we have a system to correctly detect the collision, you can set a boolean flag on the body that you want to reposition and then use an IF statement in your game loop to check if the boolean is TRUE. If it is, you simply change the x, y coordinates of the body.

The reason for using the boolean and then later setting the position is that the collision listener won’t allow you to perform actions on a physics body until the collision is fully resolved so you have to wait for the listener to have completed its iterations before you can do your next steps.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.