Collision help!

BlitzMax Forums/BlitzMax Programming/Collision help!

SLotman(Posted 2012) [#1]
Hi guys!

I'm trying to implement a collision response, into something I'm developing... but I'm stuck right now. The code:



You move the circle with the mouse. Collision is detected correctly when the mouse overlaps the rectangle - but I'm stuck trying to get the correct 'response' - move the mouse from left to right, and the circle will 'pop' on the other side - it should go "over" the rectangle.

Think of it as the slingshot on Angry Birds - if you move the bird all the way down, then move it from left to right, it touches the base of the slingshot, and "slides" above and to the right until it reaches the other side. This is what I'm trying to reproduce here!

I've ran out of ideas... does anyone have an insight for me?

Last edited 2012


Jesse(Posted 2012) [#2]
The only way I know how to solve your problem is by using vector math. if no one else helps you with it and I have some time free over the next 3 days, I might create an example for you.


matibee(Posted 2012) [#3]
Same as Jesse, I'm a bit busy right now, but the way it works is this..

Consider the rect as 4 line segments. For each line segment you have to find the distance the circle is embedded (which may depend on if you're hitting the end of the line or not) and move the cirlce back that distance alone the normal of the line (the normal is an imaginary line perpendicular to the line itself.)

All the functions for doing this are in my 2d collision demo..
http://www.blitzbasic.com/Community/posts.php?topic=85634

and there's other code around too. The Mauft vector mod can be found here..

http://www.matibee.co.uk/mbmdload/

Keywords to google: Circle vs line segment collision, Circle vs line segment sliding

The key here is "line segment" collision. A line segment is a line that only exists between two points in space. In geometric terminology a "line" is often of infinite length (a 2d version of a 3d plane.)

Let us know how you progress and I'll knock up a demo if I get change before you either solve it or someone else does.


Mauft(Posted 2013) [#4]
I think it's the last place I'll be posting it to not end up being a spammer. I've officially put the module online again, it can now be found here:

http://retrocade.net/post/138/blitzmax-vector-library

Should there ever be any updates, they'll find their way there.