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 / Vectors in Collisions

Author
Message
Braude Interactive
19
Years of Service
User Offline
Joined: 1st Aug 2006
Location: Sheffield, UK
Posted: 11th Feb 2013 22:38
Hello there.

Thanks for taking a look at my thread. I'm at a bit of a brick wall, but I'm sure you'll agree it's an interesting one.

I'm using acceleration and velocity vectors to move stuff around, and I'm trying to handle collisions using Sparky's DLL.

I basically understand vectors, and I've been using DBPro a while so I think I should be able to do this!

My problem is this, I use a ray (object's position, to the object's position + velocity) to check for collisions, and I then know the collision normal (if one exists!). I know the vector the object should be about to move on, and I know the normals.

I think that's all I should need to work out what should happen next... but I don't know how to fit it together.

I'm thinking I should resolve the velocity in the direction of the collision normal, then take the result of that away from the velocity. This should let me slide along the surface.

Am I right? Any ideas how to resolve a vector to find its component parralel to another?

Or, am I totally barking up the wrong tree here? Does anyone have any useful information for me or examples they can point me to?

There's tonnes of 2D resources out on the wide internet, but my mind boggles trying to convert it to 3D!

Code below!



Again, thanks for taking the time!
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 12th Feb 2013 00:32
Once you collide with a polygon, you take what's left of the velocity vector (the part that extends beyond the collision point) and project it alone the polygon's plane. This is what causes the sliding across surfaces.

I think this is the best source on the subject:
http://www.peroxide.dk/papers/collision/collision.pdf

"You're not going crazy. You're going sane in a crazy world!" ~Tick
Braude Interactive
19
Years of Service
User Offline
Joined: 1st Aug 2006
Location: Sheffield, UK
Posted: 12th Feb 2013 18:35
Thanks Phaelax! It was my secret hope you might be the one to respond to this, cheers
Braude Interactive
19
Years of Service
User Offline
Joined: 1st Aug 2006
Location: Sheffield, UK
Posted: 13th Feb 2013 16:01 Edited at: 13th Feb 2013 16:03
Hi again, with a little help (and some deeper though) I revised my code and it now works. I drew this diagram, and it helped me organise my thoughts, a lot!


Where the dark blue line is the object's velocity, and the light blue angle is the angle returned using the dot product. Obviously the red line is the collision normal. I wanted the player after the collision to end up with the velocity shown in green. It now works!

The collision code I used is here:


So yes, I'm pretty chuffed with that!

My next problem is also a fun one, I only want the player to be able to walk when they're colliding. And I only want them to be able to "walk" along the plane described by the normal of the collision. So somewhere in that collision code I need to work out how I can project a vector along a plane.

Any ideas?

EDIT: I know I can condense the code above quite a lot, I just left it in the simplest mathematical steps so people can follow it easily!
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 13th Feb 2013 19:07
Look at section 4 of the article, it starts to deal with collision response, such as the sliding plane which is what you want.

But basically it says:
Signed distance from original destination point to sliding plane
New destination point = destination - distance * planeNormal

"You're not going crazy. You're going sane in a crazy world!" ~Tick
Ortu
DBPro Master
18
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 15th Feb 2013 05:02 Edited at: 15th Feb 2013 05:08
Quote: "My next problem is also a fun one, I only want the player to be able to walk when they're colliding. And I only want them to be able to "walk" along the plane described by the normal of the collision. So somewhere in that collision code I need to work out how I can project a vector along a plane."


I did an 'in cover' mechanic a while back where the character would strafe or slide along a wall which sounds like what you are describing.

using the normal, you can move parallel to the surface, sliding, the same as basic strafing movement: +/- 90 degrees of facing, where in this case facing = surface normal.

This isn't using vectors, but you can adapt it



MadBit
VIP Member
Gold Codemaster
17
Years of Service
User Offline
Joined: 25th Jun 2009
Location: Germany
Posted: 15th Feb 2013 08:38
I don't know if i understand it correct. But why you not using SC_getCollisionSlideX/Y/Z ?

Share your knowledge. It's a way to achieve immortality. (Tenzin Gyatso)
Pixie-Particle-Engine

Login to post a reply

Server time is: 2026-07-07 09:05:02
Your offset time is: 2026-07-07 09:05:02