Public Group

# Collision Problem

This topic is 3614 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hello I am trying to having elastic collisions, they work half of the time but the other half the colliding objects stick together and don't let go.. Can someone help me find out why/fix this? Object is the class that contains the radius, mass, velocity, position.
void Object::check_collision(Game &game, Object &other)
{
float dx = position.x - other.get_position().x;
float dy = position.y - other.get_position().y;
//distance
float d = sqrt(dx*dx + dy*dy);

{
float Cr = 1; //Coefficiente of restitution
float m1 = mass;
float m2 = other.get_mass();
D3DXVECTOR2 v1 = velocity;
D3DXVECTOR2 v2 = other.get_velocity();

D3DXVECTOR2 Vf1 = ((Cr + 1) * m2 * v2 + v1 * (m1 - Cr * m2))/(m1 + m2);
D3DXVECTOR2 Vf2 = ((Cr + 1) * m1 * v2 + v2 * (m2 - Cr * m2))/(m1 + m2);

velocity = Vf1;
other.set_velocity(Vf2);

speed = sqrt(Vf1.x*Vf1.x + Vf1.y*Vf1.y);
other.set_speed(sqrt(Vf2.x*Vf2.x + Vf2.y*Vf2.y));

handle_collision(game, other);
}
}



##### Share on other sites
I think more info is needed here, but from what I can tell you from past experience such situations mean that even if you have a solution to a collision some objects may behave in a way to always have a collision be true, possible making the "stick" you are seeing. I'd suggest making a vector to store the position of an object in the last frame to revert to in case of a collision. Of course, that won't be smart if the last position is really far away from a high velocity object.

You may want to look at ray-triangle collisions for high velocity objects, and maybe methods like yours for more slowly moving ones. Admittedly I know nothing about ray-tri and little about the latter, but I do know those are possible avenues.

1. 1
2. 2
3. 3
Rutin
18
4. 4
khawk
14
5. 5
frob
12

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633659
• Total Posts
3013216
×