Box2d determine side of collision

Anything about development not directly related to libgdx, e.g. OpenGL, Android APIs etc.

Box2d determine side of collision

Postby zipper9998 » Thu Oct 05, 2017 8:06 pm

I have some square bodies, when they touch they join together with a weld joint, however this joint is always on the same side. How might I be able to find out the side of collision and thus the point to put the weld so that the bodies join where they collide? sorry if this sounds confusing. Thanks :)
zipper9998
 
Posts: 65
Joined: Tue Oct 25, 2016 2:05 pm

Re: Box2d determine side of collision

Postby RafaSKB » Thu Oct 05, 2017 10:01 pm

Assuming you have one joint for each side of the square, an idea is to get the collision coordinates and check for the nearest joint.

Another idea is to create a different body/fixture for each side of the square, each holding a different data object, like the number indicating the side. This can get messy with too many bodies though.
Typing Label - Label that appears as if it was being typed in real time. https://github.com/rafaskb/typing-label/
Grashers - A trash-themed roguelike in space, soon on Steam. - http://www.grashers.com
RafaSKB
 
Posts: 115
Joined: Sat Aug 01, 2015 5:14 am
Location: São Paulo, Brazil

Re: Box2d determine side of collision

Postby zipper9998 » Sat Oct 07, 2017 3:37 pm

ok thanks, I was hoping there would be a more efficient way but Ill try that :)
zipper9998
 
Posts: 65
Joined: Tue Oct 25, 2016 2:05 pm

Re: Box2d determine side of collision

Postby RafaSKB » Sat Oct 07, 2017 9:11 pm

Another thing you might wanna try is to get the local coordinates of the collision within the body, that is, the offset from the center. Maybe, just maybe, that will give you exactly what you want.
Typing Label - Label that appears as if it was being typed in real time. https://github.com/rafaskb/typing-label/
Grashers - A trash-themed roguelike in space, soon on Steam. - http://www.grashers.com
RafaSKB
 
Posts: 115
Joined: Sat Aug 01, 2015 5:14 am
Location: São Paulo, Brazil

Re: Box2d determine side of collision

Postby zipper9998 » Sat Oct 07, 2017 9:43 pm

Now that is quite a good idea, I will see what I can do, thanks again :)
zipper9998
 
Posts: 65
Joined: Tue Oct 25, 2016 2:05 pm


Return to General Development

Who is online

Users browsing this forum: No registered users and 1 guest