Jump to content
  • Advertisement
Sign in to follow this  

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.

If you intended to correct an error in the post then please contact us.

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;
	float d = sqrt(dx*dx + dy*dy);

	if(d < (radius + other.radius))
		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));
		rotation = radians_to_degrees(atan2(velocity.y, velocity.x));
		other.set_rotation (radians_to_degrees(atan2(velocity.y, velocity.x)));

		handle_collision(game, other);

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

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!