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.

DarkBASIC Professional Discussion / 2d collision system ??

Author
Message
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Aug 2010 02:15
I figured this would be simple, and the collision part is. However, it's the collision response I seem to be having issues with. Basically, the world is made up of line segments and the player is just represented by a circle.

So let's say the points {x1,y1,x2,y2] draws a line across the screen at a 45 degree angle. When the player runs into it along the x-axis, it should slowly move up slope with its remaining velocity after the collision with the line is detected. I got the collision part, but it's repositioning the circle that's got me a little stumped. Don't really have any code on hand at the moment to show (its all at home).

So basically, this is just a polygon collision system but in 2D. The thing is I've managed this sort of collision response in 3D before (but lost it of course). I have some old notes on the subject that might help me, but maybe someone can give a few pointers. Oh, and I'm not looking for any plugins either.


"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke
Sasuke
19
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 12th Aug 2010 03:08 Edited at: 12th Aug 2010 03:09
Check out this great interactive 2d physics tutorial, variable slope is what your after but each category is worth reading: 2D Physics Tutorial

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 12th Aug 2010 03:59
Vectors!!!
search "vectors don't bite" on the forum if you want to learn about vectors in general. I also made something that was just collision detection here.

Basically, the goal, where P1 to P2 is the colliding line, and C is the circle (IE position <C.x,C.y> and radius C.r) is to "Find the point where line P1 P2 intersects with a line from C in the direction perpendicular to P1 P2".
I don't really want to work through the math though... c++ operator overloading has spoiled me. Instead of typing "vector.normalize();" I need like three lines of annoying stuff. The program I wrote figures out the point of intersection during the process, so once you get the point of intersection, you can just do point collision response, which is basically this (where C is the center of the circle, P is the point you're colliding with, d is the distance between the two points, x with ^ over it is the direction from C to P, and r is the radius of the circle):


That's the notation I like to use. Unfortunately, without operator overloading or objects, that equation expands to this (given floats returning floats, seperate for x and y)


...yeh


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
Neuro Fuzzy
17
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 12th Aug 2010 04:52
voilĂ 

(because I know my code in the last demo is clear as mud. If you want to rederive it, I basically use the parametric equation from P1 to P2 intersecting with the parametric equation from C to C+<P1.y-P2.y,P2.x-P1.x> (that weird vector is perpendicular to P1 P2), then use that point for the point collision method described above. I also check point collision for the two endpoints of the line, so the circle doesn't half intersect or something)


Is't life, I ask, is't even prudence, to bore thyself and bore thy students?
Phaelax
DBPro Master
22
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 16th Aug 2010 19:42
Vectors weren't the problem, I just wasn't sure how to project the remaining velocity after collision onto the sliding plane. But I found the collision paper I was looking for by Peroxide.

Here's a quick and dirty example:



"Any sufficiently advanced technology is indistinguishable from magic" ~ Arthur C. Clarke

Login to post a reply

Server time is: 2025-05-09 07:32:14
Your offset time is: 2025-05-09 07:32:14