# 2D Collision Response - No rotation ?

This topic is 4920 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, my brain is hurting. I'm trying to find out how to do acceptable collision response between two polygons. Most of the pages found by using Google are too confusing for my simple math skills or deal with rotations also. I'm not interested in rotation for gameplay reasons. I'm simply hoping that some one can give me formula where I can plug in some numbers and then by magic I have the resulting velocities. Hopefully I can try to understand later. Suggestions on tutorials or easy to read books which cover these things are also welcome. But I'm a bit impatient so help is appreciated. Ok. This is known about my objects: My objects are 2D polygons. Collsion occurs between a point on object A and an edge on object B. Each object have a mass(scalar) and velocity(vector) (and thereby momentum). I know the impact point and I can calculate the edge normal. so now what?

##### Share on other sites
use "Newtons law of restitution for instantaious collisions with no friction"

if the objects are A and B

the relative velocity = Vrel = VA-VB

"Newtons law of restitution for instantaious collisions with no friction" is

dot(V2rel, N) = -e * dot(V1rel, N)

where V2 is the velocity after the collision and V1 is the velocity before
and e is constant standing for elasticity or coifecient of restitutuion

the impulse in entirely in the direction of the normal
because of this we can express the impulse as some number j time the normal,
giving j*N

since forces are equal and oppisite the impulse felt by B is -j*N

we have

V2A = V1A + j/ma*N
V2B = V1B - j/mb*N

since j is a moment and we need velicity so we solved by dividing by mass

as above exept replace rel with the vectors

dot ( V2A - V2B, N ) = -e * dot( V1A - V1B, N)

and we want to solve for j our impulse magnitute

after subsitution equation we get
dot(VA1, N) + dot(j/ma*N, N) - dot(VB1, N) + dot(j/mb*N, N) = -e * dot(V1A - V1B, N)

and solve for j

j = (-(1+e)*dot(V1A-V1B, N))/(|N|^2*((1/ma)+(1/mb))))

now just do

VA += N*j
VB -= N*J

this is pretty much straight from the chris hecker stuff. so if you dont get i suggest reading it. Just google "Chris Hecker Physics"

##### Share on other sites
That works for any kind of rigid bodies (polygons or not), and ignoring rotations.

assumptions :
object (0) has mass 'm0', velocity 'v0' and colliding edge 'e0'.
object (1) has mass 'm1', velocity 'v1' and colliding vertex 'p1' (unsused).

edges in polygons are ordered counter-clockwise. If not, the normal will be pointing inwards in polygon 0.

// normal of collision, // in this case, a vector perpendicular to edge direction 'e'.vector n(-e0.y, e0.x);// make vector length = 1.0f (important)float n_length = sqrt(n.x*n.x + n.y*n.y);n /= n_length;// relative velocityvector v = v1 - v0;// impact velocity, or how much 'velocity' going against the edgefloat vn = v.DotProduct(n);// objects are separating, no impulse.if (vn > 0.0f) return;// coefficient of retitution (in range 0, 1), or how much 'bounce' you wantfloat restitution = 0.5f;// collision impulsefloat j = (-(1.0f + restitution) * vn) / ((1 / m0) + (1 / m1));// apply the impulse to the object's velocity.v0 -= (j / m0) * n;v1 += (j / m1) * n;

This is pretty much what raymond wrote, in another form.

##### Share on other sites
Thanks guys, I'm at work now, but I will look at it when I get home.
If what you wrote works I will write you into my will :)

I did come across Cris Hecker but I seem to remember that he wrote on his website that the pdf documents messed up notations so for that reason I skipped it. Being inexperinced with math and physics I could probably not detect those errors.

I even have "Physics for game developers" but I thought it was a bit difficult to follow. When I get the time I must read it from start to finish or buy another book. Just learning the basics of motion, momentum etc. is actually more interesting than I thought.

Thanks again, I really hope it works. I've been stuck for weeks because of this.

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• ### Forum Statistics

• Total Topics
634136
• Total Posts
3015757
×