#### Archived

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

# line and rectangle collision detection question

This topic is 5356 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 on other sites
btw,its a 2D game.

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

1. 1
2. 2
3. 3
Rutin
13
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633700
• Total Posts
3013418
×