Skip to main content
gamedev.net
🔒 Locked

collision response

Started by tendifo Apr 3, 2007 at 12:54 AM 2 replies 1k views
Original Post
tendifo
tendifo
My nice little picture describes the situation at hand, which is a simple collision between two spheres. http://www.filepub.com/public/pview/6925/collision.gif From what I've gathered (mostly from http://www.cs.cmu.edu/~baraff/sigcourse/index.html), first what you do is split the velocities for both sphers into two orthoginal components, the tangent and normal. In one of the papers, to find these, the following equations are used: n = normalize(p1 - p2); vn = (n . v)v vt = v - vn This sounds simple enough.. but it doesn't seem to be working right for me. A few questions: 1) Should n be facing the sphere whose velocity you're trying to split up? That is, should the normal in the picture be used to find the components for v1, and the negated n be used to find the components for v2? Maybe opposite? 2) Should the v within the dot product in the first equation be normalized? That seems to help my problem somewhat. Maybe there's something I don't know that I'm completely missing? Thanks in advance!
oliii
oliii
You're on the right track, but you first combine the spheres velocity into one relative velocity, and work from there.

As for which way the normal is pointing, it depends entirely which way you do your relative velocity, and your conventions, but usually...

// collision detectionVector N = (P1 - P2);float dist = N.Length();float depth = (r1 + r2) - dist; // depth of intersection// Collision detection. Spheres dont touch.if(depth < 0.0f) return false;// normal of collisionN /= dist;// separation of the spheres (so that they stop intersecting)Vector Sep = N * depth / (1/m1 + 1/m2); P1 += Sep * (1/m1);P2 -= Sep * (1/m2);// The impact velocityVector V = (V1 - V2);float vn = V.DotProduct(N);if (vn > 0.0f) return false; // the objects are separating. No response// The split componentsVector Vn = N * vn;Vector Vt = V - Vn;// The collision impulsesVector Jn = Vn * (-(1.0f + CoR) / (1/m1 + 1/m2)); // collision impulse.Vector Jt = Vt * (-(CoF)        / (1/m1 + 1/m2)); // friction impulse.// The changes in momentumV1 += (Jn + Jt) * (1/m1);V2 -= (Jn + Jt) * (1/m2);


then you can look at this as an example.
Everything is better with Metal.
tendifo
tendifo
Can't I just find the normal and tangent components to each velocity vector. Then take the magnitude of each normal component, and then use the normal momentum/kinetic energy equations to find the new velocity and thus the response vector. I don't have friction yet, so I'd leave the tangent vector alone. Then I'd add them together to get the new velocity vectors. Does that work? If not, I'll try your way.

Thanks.
oliii
oliii
You can try. I any case, you should achieve the same result.
Everything is better with Metal.

Topic Locked

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

Sign in to reply to this topic.