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


collision detection

Recommended Posts

O_o    175
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
porthios    130
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