Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

O_o

collision detection

This topic is 5306 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 doing some collision detection in my game and I need to find the intersection of a line and a plane for a pong type game. Ok fine I can do that but now I want to restrict the plane to a square of finite size. Given the plane, the center point of the square, the length of the squares sides and the point of intersection how would I go about calculating if the point of intersection lies in the square.

Share this post


Link to post
Share on other sites
Advertisement
I would consider this similar to a Vector->Rect type of collision. Ok, here''s the way I came up with, but I don''t know if it''s the best or most efficient way. Basically I find the y value of the vector at the left and right sides of the Rect, and check to see if this y-value is within the Rect y-values. Here''s how to calculate the y value of the vector:

slope = (y2 - y1) / (x2 - x1)

Y_Val_At_Left = Vector.Top + (Rect.Left - Vector.Left) * slope
Y_Val_At_Right = Vector.Top + (Rect.Right - Vector.Left) * slope

Then you''d check to see if Y_val_At_left or Y_val_At_Right is withing the Top and Bottom of the Rectangle.

Im making the assumption that you can interpret this badly stated post! Good luck!

Share this post


Link to post
Share on other sites
Game Tutorials has a great explanation about it, you can see it inside the OpenGL section, page 3

http://www.gametutorials.com/Tutorials/opengl/OpenGL_Pg3.htm

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!