Jump to content
  • Advertisement
Sign in to follow this  
redneon

Collision detection on a slant

This topic is 4410 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

I'm thinking of writing a simple pinball game but one of the first questions that has been puzzling me is this... How am I going to make the ball roll down a slanted plane? I understand the basic physics required to implement gravity and such, and understand collision detection to the point of ¨If the ball has touched or passed through this block then set it's position to the block¨. This is all well and good for basic stuff like checking if the ball has collided with a plane that is flat along the Z. Because all I have to do is check to see if the ball has arrived at the Y position of the plane. But I'm not sure how I would do it when the plane is slanted. Can anyone offer me any tips or point me in the right direction as to how I can find out more information?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
of all the possible angles that a plane may lie on, one that is flat and perpedicular to Z is one in ad infinitum.
You should code your collision detection to be general for any angle, the Z plane is just a specific case; not the other way around.

I like to do vector reflection of the ball's path (taking into account time passed to determine how far away it bounces)
as well as reduction in velocity due to energy lost.

Vector reflection can be accomplished using only the incoming ball vector, and the plane's normal vector. If sin or cos show up, you are doing it wrong.

Share this post


Link to post
Share on other sites
The easiest way to think of collision detection/avoidance is to picture one moving object, and one stationary object at (0, 0). In this case, the pin-ball will be moving at velocity V and accelerationg by A. The slanted bumper is the stationary object. Problem is, its not flat at (0, 0), but you can fix that with a little trig.

You basiclly want to "view" the V and A vectors from the slant. First thing to do is find out how far you'd have to move the slant to put it at (0, 0), then the angle you'd have to rotate the slant to make it flat. By applying the inverse of each of these operations to V and A, you have effectily created a world in which your slant is the X axis.

Share this post


Link to post
Share on other sites
You may want to check out this article... :)

It's a thorough explanation of the Separating Axis Theorem, which basically comes down to projecting the objects on the edge normals of the other object. In your case, since you´re working with a ball, you can just project the ball's center on the plane normal, and see if the absolute value of the result is more or less than the ball's radius. You can then move the ball back along this plane normal if it collides.

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!