Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / Line ball collision

Author
Message
netmon
18
Years of Service
User Offline
Joined: 14th Aug 2006
Location:
Posted: 3rd Feb 2007 15:22
Click on the circle and toss it around. I threw in a bezier curve as this when what I will eventually be colliding against. I know there a few bugs, but this explains how collision at an angle work.

NeX the Fairly Fast Ferret
19
Years of Service
User Offline
Joined: 10th Apr 2005
Location: The Fifth Plane of Oblivion
Posted: 3rd Feb 2007 21:06
Doesn't compile.


Since the other one was scaring you guys so much...
Kohaku
20
Years of Service
User Offline
Joined: 3rd May 2004
Location: The not very United Kingdom
Posted: 3rd Feb 2007 21:23
Works for me with the latest version of DBP*.

It's neat - it would be interesting to see it working with some more circles and obstacles.

*at the time of writing.


You are not alone.
Alquerian
18
Years of Service
User Offline
Joined: 29th Mar 2006
Location: Reno Nevada
Posted: 4th Feb 2007 04:49
It compiled ok for me, interesting demo.

Quit planning to make a game and make a game.
Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 4th Feb 2007 19:16
if you throw it fast enough, the circle goes through the line

Who needs a signature?
netmon
18
Years of Service
User Offline
Joined: 14th Aug 2006
Location:
Posted: 4th Feb 2007 20:06
Like i said, it has bugs I was trying to work on that though. I would implement some oldx oldy routine to solve that, i think.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Feb 2007 22:42
Yea just make a velocity vector from the old and new coordinates and check for line intersection.

Milkman
18
Years of Service
User Offline
Joined: 30th Nov 2005
Location: United States
Posted: 4th Feb 2007 23:52 Edited at: 4th Feb 2007 23:56
Quote: "Yea just make a velocity vector from the old and new coordinates and check for line intersection.
"


But then you don't have the width of the circle, it's just a line intersecting another line.

What you should probably do is circle casting; it can be done somewhat like this:


Who needs a signature?
netmon
18
Years of Service
User Offline
Joined: 14th Aug 2006
Location:
Posted: 5th Feb 2007 12:44
why not say,

if bally# < liney# && oldy# > liney#
bally# = liney# + radius
dragging = 0
`maybe set another variable to a state so you dont grab the ball again to fast
endif

i'll try this a little later. Or something close to it
netmon
18
Years of Service
User Offline
Joined: 14th Aug 2006
Location:
Posted: 5th Feb 2007 18:55
After thinking about this more and trying out some things, I believe you will need to rotate the oldy position. Also, you may need to add an old y velocity part in there to. Need to think this one over more.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Feb 2007 22:23 Edited at: 12th Feb 2007 22:27
Quote: "But then you don't have the width of the circle, it's just a line intersecting another line"


Two solutions that I can think of for that. The first is you just transform the space so that the circle is only 1 unit. (this is probably common in large-scale collision system when dealing with an ellipsoid and polygon soup)

The other is it simple make line segment of the circle's movement longer.

A = old position
B = new position
D = normalized direction vector of circle's movement
r = circle's radius

D = normalize(B-A)

A = A-D*r
B = B+D*r

Then use AB as the line segment of the circle.

In this illustration, the red lines represent the extensions of the circle's line segment. This should help you see why this accounts for the radius.




This code snippet checks for line-circle intersection, but does not consider movement, just a simple overlap test.


I also have a snippet showing collision detection with a hermite spline if you want to see it, but you can probably figure that one easily I'm sure.

Attachments

Login to view attachments
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Feb 2007 04:43
Here's a moving sphere-plane collision explained, it's basically a 3D version of a circle-line.
http://www.gamasutra.com/features/19991018/Gomez_1.htm

RUCCUS
19
Years of Service
User Offline
Joined: 11th Dec 2004
Location: Canada
Posted: 14th Feb 2007 02:54
Im not sure if this will help or not, I havent read through the code yet, but it looks like all you need to do is feed the function in that link the old coordinate of the ball and the new coordinate, and the position of the line segment ends, just make the intersection line start directly infront of the ball by it's radius, and end directly behind, and I think it'll work.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 14th Feb 2007 20:19
That's pretty much what my illustration above shows to do. Granted I haven't tested that, but it should work.

Login to post a reply

Server time is: 2024-11-23 00:01:37
Your offset time is: 2024-11-23 00:01:37