Skip to main content
gamedev.net
🔒 Locked

collision detection

Started by O_o 2 replies 750+ views
Original Post
O_o
O_o
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.
porthios
porthios
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!
dark_vision
dark_vision
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

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.