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 / realistic 2d collision help

Author
Message
noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 29th Dec 2010 17:41 Edited at: 29th Dec 2010 17:43
i want to add realistic asteroid-ship collision to my game "2D space" (can be found in program announcements.) i dont know how to get the normals from a circle primitive and thus i cant produce the desirec collision effect, where the player bounces off the asteroid in the correct direction. The image is made with a paint app on my phone so its not very precise but u get the idea.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 29th Dec 2010 22:08 Edited at: 29th Dec 2010 22:09
the thing is, the normal of collision of a sphere will *always always always* be perpendicular to its surface. That means it will always be (the normalized value of) a point on its surface minus its center.

Finding circle<->circle collision is super easy (due to the property above). Circle<->oval collision is a bit harder. Circle<-> square is hard (especially if the square can rotate - then you have to worry about rotational velocity and moment of inertia). Circle <-> rectangle is kinda the same but a bit harder than circle<->square. And then if you have a bunch of squares overlayed on each other? That's even a bit more complicated.

Uhh, so I'd say you should either try box2d, use newton physics restricted to 2 axes (no concave shapes tho), or implement a system like this:
http://www.gamedev.net/reference/programming/features/verletPhys/default.asp (accurate looking physics, but don't mistake it for actual physics! It's just gamey shortcuts. Also the example code is in C++)

If you want to have only circle-circle collision *with* rotation, that's a lot easier. Something like I did in these two videos:
http://www.youtube.com/watch?v=28G7k0MTfxg
http://www.youtube.com/watch?v=cQ1n1-ls2CQ&t=2m8s
would work.

The source code for the first video has been uploaded (its in c++), and I'll get the source uploaded for the second vid (its in java).
[edit]
but box2d would really be the best option unless you really don't want to spend

noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 30th Dec 2010 00:51
thanks! I figured out a simple way of doing circle circle collision, which i will stick to for simplicity and speed, i will check the vids when im on a computer, im pn my phone now also i surely will check my physics book for any info didnt quite get hat u meant with the perpendicular phrase, english isnt after all my main language
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 30th Dec 2010 01:13 Edited at: 30th Dec 2010 01:14
What I mean is illustrated in this picture:

You've probably taken geometry, but if you haven't, those (poorly drawn) right brackets mean right angle:


So your picture of "collision" with lines coming out every which way on the circle is incorrect. Those aren't surface normals of the sphere - and in perfect rigid body collision, force is only transferred in the direction of a surface normal (negative or positive).

noobnerd
15
Years of Service
User Offline
Joined: 30th Nov 2010
Location:
Posted: 31st Dec 2010 00:05
yes, i understand that now, the lines on my ill drawn circle are not normals, but the desired effect of the collision, meaning, if the ship come with that angle, the second line was the supposed angle after bouncing off.

Login to post a reply

Server time is: 2026-07-18 07:33:01
Your offset time is: 2026-07-18 07:33:01