Joint for two overlapping bodies (can't get it working)

Topics: Developer Forum
Mar 27, 2013 at 5:52 PM
Hey this is probably really simple,

but I'm trying to make a joint between two bodies when I press a button (a lot like the mouse joint in the samples).

my first body is always the same, and it has no collision, so it can overlap another body in the same world. How can I test if there's a body under the first one, and create a joint between the two if so?

Thank you!
Mar 27, 2013 at 7:55 PM
Edited Mar 27, 2013 at 7:57 PM
Depends on what you mean by "under the first one". Do you mean behind it (i.e. same x and y but different z), or do you mean below it (i.e. same x, smaller y)?

If you mean behind it, then you can just use collisions (not sure what you mean when you say "has no collision" -- do you mean it is a sensor?).

If you mean underneath it, then you can add a sensor fixture to the first body that extends beneath it (picture a magnetic field under a magnet). Then you can check collisions on this sensor to find any bodies to connect.

With some more info (describe what the game is or what you're trying to do in more detail) I may be able to help you more.

Good luck,
Mike.

Edit: oh, rereading your post subject I can see you mean underneath (or overlapping). You should just make your body a sensor (i.e. has collisions but does not react to the them) and then add an OnCollision handler.
Mar 27, 2013 at 9:21 PM
well I'm just working in a 2D environment here, and the first body is in a collision category that does not collide with other bodies, that's all it is.

I'll try to work with sensors like you suggested.
Mar 27, 2013 at 9:25 PM
well I'm just working in a 2D environment here, and the first body is in a collision category that does not collide with other bodies, that's all it is.

I'll try to work with sensors like you suggested.