Skip to main content
gamedev.net
🔒 Locked

Collision Response

Started by TheC00L1 Jun 1, 2006 at 7:25 PM 7 replies 1.2k views
Original Post
TheC00L1
TheC00L1
I need 3D collision response help, for meshes, particularly two triangles. I know where the collision is, x-y-z/barycentric, but have no clue how to react to it, do you know anything about it? Like, am i suppose to move the meshes back to the exact point of collsion and then bounce them off each others triangles, or is there a better way?
A wiseman once said nothing, but no one was there to hear it.
Stemic
Stemic
You can try these articles about physics in games.

http://www.d6.com/users/checker/dynamics.htm#articles

It atleast explains 2D collision response in an very understandable way. I haven't read the 4th article that is supposed to make the bridge between his 2D formulas and an 3D environment, though, but maybe that article just as good as the previous ones.

Oh and yes, in the source provided in his 2D example, he does run the simulation to the point of objects colliding and not penetrating before bouncing them off, just like you thought.

Maybe you just want a simple bounce, by changing direction of the velocity vector or changing direction of one of its components. (In pong, if the ball bounces to the top of the screen, the velocity y-component is just multiplied by -1)

Good luck :)
TheC00L1
TheC00L1
Yeah i got the reaction, one mesh will move in the relfected vector off the other's normal, but i can figure out how far to move it back, jus right before the collision, i don't want my character going through walls.

But it looks like the articles are adressign stuff like that, so thanx! :)
A wiseman once said nothing, but no one was there to hear it.
TheC00L1
TheC00L1
But it doesn't explain how to find the point right before, or on the collsion, does anyone know how to find the point of collision?

Like, the two triangles are overlaping, and i want to move them back, just right before the collision happened. Help? Anyone?
A wiseman once said nothing, but no one was there to hear it.
Bob Janova
Bob Janova
Do you know which two surfaces (triangles) are involved in the collision? If you do you can calculate the distance before and after the frame and calculate at what time the collision occured. You can then 'unmove' the objects to that position, calculate the new bounce velocities and 'move' the objects apart for the remainder of the frame. (Bear in mind that the objects may collide again in the remaining time, particularly if the collision point gives them considerable angular momentum, or with other objects.)

If that's what you meant then I'll post some pseudocode for you if that's not a good enough explanation.
TheC00L1
TheC00L1
YES, that is exactly what i meant, to "unmove" it.

And, yeah i know the surface normals, the previous positions, and the two points of collision.

The pseudocode would be cool!

Could you also include new motions?, i know it has to reflection of the surface normals, but i rather not waste time wondering if you know it, but if you can't that's fine.
A wiseman once said nothing, but no one was there to hear it.
Bob Janova
Bob Janova
Okay, let's see. Bear in mind that I just made this up on the spot :P.
float GetCollisionTime(Vector p1, Vector p2, PhysicsObject obj1, PhysicsObject obj2){ // Points p1, p2 are the collision points on the two objects, // after collision Vector relativeVelocity = obj2.Velocity - obj1.Velocity; float distanceAfter = DotProduct(p2 - p1, relativeVelocity); // 'Unmove' the collision points to find distance before // NB A better 'point unmove' is required if you have angular motion float distanceBefore = DotProduct(  (p2 - obj2.Velocity) - (p1 - obj1.Velocity),  relativeVelocity);  // Time that happened before collision return (distanceBefore / (distanceBefore + distanceAfter)) * lastFrameLength;}void Move(PhysicsObject obj1, PhysicsObject obj2, float time){ obj1.Position += obj1.Velocity * time; obj2.Position += obj2.Velocity * time;}void DoCollision(PhysicsObject obj1, PhysicsObject obj2){ // Get the collision point (you already know this) Vector[] points = GetCollisionPoints(obj1, obj2); float unmoveTime = GetCollisionTime(obj1, obj2, points[0], points[1]); // Negative move = unmove :) Move(obj1, obj2, -unmoveTime);  // Not listed DoCollisionResponse(obj1, obj2);  // Move the new velocities for the remainder of the frame, but // test for new collisions afterwards Move(obj1, obj2, lastFrameLength-unmoveTime);}


The collision response depends on how realistic your physics is supposed to be. Do you do a simple elastic bounce, a simple elastic bounce with angular motion (this is what I guess you want to do), or something more advanced with 'squishy' materials. I can't remember how to do anything beyond a simple point-particle bounce at the moment.
TheC00L1
TheC00L1
Thanx, i'll give it a try, but jus one more question, these two points(p1,p2) are the points that result from the intersection of triangles, right?
A wiseman once said nothing, but no one was there to hear it.
Bob Janova
Bob Janova
Yes – they're the points on the two objects which are in collision, as determined by your collision detection algorithm.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.