Public Group

# Collision Bouncing

This topic is 3623 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 have my collisions cause the objects to bounce from one another hoewever when my objects collide they seem to attract each other(Although not always sometimes they do bounce, or not bounce at all) I don't know what I am doing wrong, any help would be appreciated. Thanks
	float dx = position.x - other.get_position().x;
float dy = position.y - other.get_position().y;
//distance
float d = sqrt(dx*dx + dy*dy);

{
D3DXVECTOR2 momentum;
momentum.x = mass * velocity.x;
momentum.y = mass * velocity.y;
float Cr = 1; //Coefficiente of restitution

velocity = ((Cr + 1) * other.mass * other.velocity + velocity * (mass - Cr * other.mass))/(mass + other.mass);
other.set_velocity(((Cr + 1) * mass * velocity + other.velocity * (other.mass - Cr * mass))/(mass + other.mass));
speed = sqrt(velocity.x*velocity.x + velocity.y*velocity.y);
other.set_speed(sqrt(other.velocity.x*other.velocity.x + other.velocity.y*other.velocity.y));

handle_collision(game, other);
}


[Edited by - Antonym on January 17, 2009 1:54:41 PM]

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633763
• Total Posts
3013728
×