#### Archived

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

# 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.

## 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 on other sites
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 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 on other sites
Flipcode has a great collision detection tutorial here. I have also found this page to be very helpful in triangle-level collision detection.

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5

• 27
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631737
• Total Posts
3001944
×