Archived

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

line and rectangle collision detection question

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

in my game,i have some walls which represented as line and there is a bounding box around my sprite.what i wanna do is check the collision between the wall and the sprite.it is easy to do when either end of the wall is in the bounding box,but im stuck on part of the line is in the box.how shall i detect such a collision?thanks in advance.

Share this post


Link to post
Share on other sites
Make the line divide your surface in two halves. Calculate which half each of the box vertices is in. If all vertices are in the same half, you don''t have a collision, else you do.

Calculating point-in-halfspace is a simple dot product and comparision.

Share this post


Link to post
Share on other sites
thanks for the reply.actually i jus came up with a idea on my own.since i have the line equation and the x or y for every dot that make up the box,i can put the x or y into the equation and get the respective value and check if it is one of the dot on the edge.do you think it will work?and which one of the two ways is better?thanks.

Share this post


Link to post
Share on other sites