Archived

This topic is now archived and is closed to further replies.

Ender81X

3D Object Collision Reaction

Recommended Posts

Well, I am trying to implement collision reaction with 3D objects to create the famous "sliding" effect, so my character models can slide along walls when they collide with them. I current track the model''s position (x,y,z), and direction of movement. The direction of movement is not in a vector, but in rotation about the x,y,z axis. I think this is convertable to a vector, but I''m not sure how to do it. When my object collides with another object, I retrieve the points of the triangle that it collided with. I think sliding has something to do with the normal vector of that triangle, but I''m not sure...can anyone help me out here? How can i figure out the direction that my player should slide in? I assume I can use this same calculation to implement gravity, which would be nice. I''m not a math buff, but I understand enough that an explained answer should suffice. Thanks in advance for the help!! -Chris Ayoub

Share this post


Link to post
Share on other sites
Well, I''m glad some can actually call it Collision Reaction, and not Collision Detection : )

Anyways...

Basically...you have our approach vector, yes you need that...and you have the normal of the wall. You basically want to remove all of the approach vector that opposes the normal vector.

So like, if you''re coming straight at the wall, your approach and normal vectors nullify each other.

So how do you do this? Add them : ) Or something. I''ve never actually done this, but as long as both vectors are normalized (meaning same length), adding them should give you something useful...Your modified approach vector shouldn''t have any values that are opposing the original tho...like just adding the two vectors could give you a result that pushes back from the wall. You would need to make that value 0 instead. Try it, let us know ; )

G''luck,
-Alamar

Share this post


Link to post
Share on other sites
Thanks for the quick reply! My only problem now is how do i take the information i have (rotation about each axis), and turn that into a vector? if my object is facing straight forward, then all rotations are 0, if it is facing to the right, rotationY=90,rotationX=0,rotationY=0. I guess the only axis that has rotation is the Y axis since the character is always standing straight up, just turning in circles...anyone know how to convert that into a 3d vector? Am i just missing something obvious?! thanks again for the quick reply.
-Chris

Share this post


Link to post
Share on other sites
Ahem... (this should really be in the Math and Physics forum; you''ll get great, detailed answers there, so ask the moderator to move it for you )

Okay. If you have a normalized velocity vector {x,y,z} and a normalized surface normal {a,b,c}, adding them will yield alteration of motion, but not necessarily what you want. Your object may continue moving in the direction of the plane. I always advocated finding the cross product of the two vectors and then rotating them about the original velocity vector, but I know that there''s a better way. Check the M&P forum; there was a recent thread on exactly this (actually, there''s tons of recent threads on exactly this).

And as for converting rotations to vectors, why not rotate a vector from a "default" position/direction like {1,1,1}. The rotation can be concatenated into a single matrix.

Good luck.

Share this post


Link to post
Share on other sites
Oh, almost forgot: you can use simple vector addition to simulate gravity because gravity, like velocity, is a vector - it has magnitude and direction. The normal of a surface, OTOH has direction but zero magnitude, disqualifying it as a vector in the "physical" sense.

And I hope I just made sense.

Share this post


Link to post
Share on other sites