Perfect Collision between Point and Rectangle
2 replies to this topic
Members - Reputation: 100
Posted 18 May 2011 - 02:23 AM
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.
Members - Reputation: 267
Posted 18 May 2011 - 02:57 AM
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.
Crafter 2D: the open source 2D game framework