Making two colliding triangles stick by sides

Official forum for the Chipmunk2D Physics Library.
Post Reply
Skyliner
Posts: 1
Joined: Mon May 06, 2013 4:04 pm
Contact:

Making two colliding triangles stick by sides

Post by Skyliner »

Hello everyone,

I am attempting to create a simulation that uses floating triangles, which upon collision of their sides, should stick to each other and form a new entity. That is, if two triangles collide but their collision point is one of the three vertices on the perimeter of the triangle, it should not stick. But if two triangles collide their sides and there is significant overlap, they should form a new figure (Think of two equilateral triangles colliding and forming a perfect rhombus).

I am having trouble using the collision callback and types of joints to achieve this. Right now, I have the collision handler checking if the distance between the two colliding equilateral triangles is <= their width, since I have defined their width to be twice the distance from the center of the equilateral triangle to the border/side. But when I try to add a PinJoint or PivotJoint using the collision points or centers of the colliding triangles, I get odd behavior where some stick together and some don't and after a few seconds the triangles go berserk and leave the screen, eventually crashing the app.

Some of this might be due to overlap when colliding, since physically the collision points should never be < the width as defined above (and the only time they should be equal is when two triangles perfectly collide), but on printing out distances I found many to be much less than this width.

I'm beginning to think I might have to just do away with joints and delete the two objects and add the new resulting object, but I was wondering if anyone knew how to do this with joints and collisions as it intuitively should be.

Thanks
Post Reply

Who is online

Users browsing this forum: No registered users and 43 guests