Explosive tangent impulses causes extreme rotation

Started by
11 comments, last by Finalspace 9 years, 10 months ago

Don't get too discouraged, if you are doing it for the purposes of learning a physics engine, I think the current path you are heading down is completely fine, and a little frustration and debugging are normal and part of the process.

On the other hand, if your desire is to just get the game part started, then I'd probably just expand box2d lite.

Advertisement

Oh it seems i fixed it. The relative velocity for angular rotation was incorrect - now it works :-)

Original box2d lite:

// Relative velocity at contact
dv = b2->velocity + Cross(b2->angularVelocity, c->r2) - b1->velocity - Cross(b1->angularVelocity, c->r1);
my old impl:
var tempVec = Vec2Pool.get();
var rva = Vec2Pool.get();
var rvb = Vec2Pool.get();
math.vec2CrossSV(tempVec, bodyA.angularVelocity, contact.rA);
math.vec2Add(rva, bodyA.velocity, tempVec);
math.vec2CrossSV(tempVec, bodyB.angularVelocity, contact.rB);
math.vec2Sub(rvb, bodyB.velocity, tempVec);
math.vec2Sub(relVelocity, rvb, rva);
new working impl:
var tmp = Vec2Pool.get();
math.vec2CrossSV(tmp, bodyB.angularVelocity, contact.rB);
math.vec2Add(relVelocity, bodyB.velocity, tmp);
math.vec2Sub(relVelocity, relVelocity, bodyA.velocity);
math.vec2CrossSV(tmp, bodyA.angularVelocity, contact.rA);
math.vec2Sub(relVelocity, relVelocity, tmp);
Javascript does not support operator overload - therefore i needed to make this ugly code -.-

Ah i am really happy right now, now i can go to the next step, implement contact caching + warm starting, better broadphase and finally polygon bodies.

If you want to see my progress, you can check my youtube channel frequently - i upload there things i have made - but mostly in javascript tongue.png

Thread can be closed.

This topic is closed to new replies.

Advertisement