Jump to content

  • Log In with Google      Sign In   
  • Create Account

Perfect Collision between Point and Rectangle


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 rap1357   Members   -  Reputation: 100

Like
0Likes
Like

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.

Thanks

Sponsor:

#2 jeroenb   Members   -  Reputation: 257

Like
0Likes
Like

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

Blog: Crafter 2D
Twitter: @crafter_2d


#3 Rene Z   Members   -  Reputation: 516

Like
2Likes
Like

Posted 18 May 2011 - 03:12 AM

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS