Sign in to follow this  
rap1357

Perfect Collision between Point and Rectangle

Recommended Posts

rap1357    100
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 this post


Link to post
Share on other sites
jeroenb    282
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 this post


Link to post
Share on other sites
Rene Z    605
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this