Public Group

# Perfect Collision between Point and Rectangle

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

## Recommended Posts

Using the Separating Axis Theorem, I know how to detect if a point is inside a rectangle very easily. The problem is, if the rectangle is too small or the point is moving too fast, it is never actually inside the rectangle because in a single frame it will move to the other side of the rectangle. What is the best way to detect if the point is ever going to move through the rectangle? Basically, so that I can perfectly detect when a collision between a moving point and rectangle occurs.

Thanks

##### Share on other sites
You can do it like some continuous physics libraries do it. They split of the movement of the point and divide it into smaller timesteps. Then for each step it checks if there was a collision. This works for most problems, though when you are moving tooooo fast and the rectangle quite small, it might not detect it as the resulting timeslice still is too big. You can tweak this for your game by altering the update frequency, movement speed and decreasing/increasing the timeslice of the detection system.

##### Share on other sites
Or do a line segment - rectangle test, where the line segment starts at the previous position of the point and ends at the new position. That should work for all circumstances.

• 32
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631352
• Total Posts
2999483
×