Vehicle/Rigid Collision Fixes
by Ross Pawley · in Torque Game Engine · 06/11/2007 (10:23 pm) · 115 replies
Hey everyone, I just wanted to post these early fixes to the frequent and frustrating vehicle collision problems people have had with TGE. We spent a few hours today at the office going through things and this new code works relatively well with some small issues, mainly interpenetration. However, it's a far sight better than what was there, which was just calling into the collision routine for immobile ridgid objects (and thus unsuitable for vehicles entirely).
In rigid.cpp replace these functions:
(CONTINUED)
In rigid.cpp replace these functions:
bool Rigid::resolveCollision(const Point3F& p, Point3F normal, Rigid* rigid)
{
atRest = false;
Point3F v1,v2,r1,r2;
getOriginVector(p,&r1);
getVelocity(r1,&v1);
rigid->getOriginVector(p,&r2);
rigid->getVelocity(r2,&v2);
// Make sure they are converging
F32 nv = mDot(v1,normal);
nv -= mDot(v2,normal);
if (nv > -0.001f)
return false;
// Compute impulse
F32 d, n = -nv * (1 + restitution * rigid->restitution);
Point3F a1,b1,c1;
mCross(r1,normal,&a1);
invWorldInertia.mulV(a1,&b1);
mCross(b1,r1,&c1);
Point3F a2,b2,c2;
mCross(r2,normal,&a2);
rigid->invWorldInertia.mulV(a2,&b2);
mCross(b2,r2,&c2);
Point3F c3 = c1 + c2;
d = oneOverMass + rigid->oneOverMass + mDot(c3,normal);
Point3F impulse = normal * (n / d);
applyImpulse(r1,impulse);
impulse.neg();
rigid->applyImpulse(r2,impulse);
return true;
}
bool Rigid::resolveCollision(const Point3F& p, Point3F normal)
{
atRest = false;
Point3F v,r;
getOriginVector(p,&r);
getVelocity(r,&v);
F32 n = -mDot(v,normal);
if ( n < 0 )
return false;
// Collision impulse, straight forward force stuff.
F32 d = getZeroImpulse(r,normal);
F32 j = n * (1 + restitution) * d;
Point3F impulse = normal * j;
// Friction impulse, calculated as a function of the
// amount of force it would take to stop the motion
// perpendicular to the normal.
Point3F uv = v + (normal * n);
F32 ul = uv.len();
if (ul) {
uv /= -ul;
F32 u = ul * getZeroImpulse(r,uv);
j *= friction;
if (u > j)
u = j;
impulse += uv * u;
}
//
applyImpulse(r,impulse);
return true;
}(CONTINUED)
#102
Why not use ODE?
I think you answered your own question!
Seriously though, although I plan to do exactly that, I just don't have the year-long resource at the moment to get it done. It'd be swell to get "stock" Torque rigidbody physics to be competent in the meantime. Ross got us past the machine-lockup stage (for which I still have warm fuzzies of gratitude). It'd be nice to take it a little further.
08/09/2008 (9:34 pm)
It takes me one year to integrate ODE with Torque.Why not use ODE?
I think you answered your own question!
Seriously though, although I plan to do exactly that, I just don't have the year-long resource at the moment to get it done. It'd be swell to get "stock" Torque rigidbody physics to be competent in the meantime. Ross got us past the machine-lockup stage (for which I still have warm fuzzies of gratitude). It'd be nice to take it a little further.
#103
08/20/2008 (6:32 pm)
@Henry: you haven't changed your mind, have you? :-o
#104
08/21/2008 (11:58 am)
@Justin: I think the ODEItem implementation only uses ODE for collision resolution though? The problems with collision detection are more serious in TGE, I think..
#105
So you'll notice at the very end it pauses, it'll hang like that until I kill the game.
Thx.
05/29/2009 (1:08 pm)
Hello, well I have been searching the forums for quite some time now to try and figure out why my game keeps crashing. I kind of have an understanding of what's going on but don't really know how to fix it. Since this whole forum post seems to be along the same lines as my issue I'm hoping that someone might know a solution or a suggestion. Oh and this is with Ross Pawley's code that was posted on page 1. When I am in control of a flying vehicle it destroy's itself fine as long as the flying vehicle's angle of collision to the surface of a dif or whatever is not less than.......roughly 10 degrees?. If it's almost parallel to the surface when it collides it stops and just hangs. Here's the video:So you'll notice at the very end it pauses, it'll hang like that until I kill the game.
Thx.
#106
DALO, wish I could help you, but my game doesn't use any DIF objects. Vehicles+Torque = Pain in the Butt, it turns out.
One major purchase decision regarding Torque3D for me will be whether or not this ever got fixed.
07/06/2009 (9:06 pm)
I'm having a hell of a time getting RigidShapes to collide with Vehicles without crashing! I put in this fixed code to both RigidShape and Vehicle, and followed Lee Latham's advice in post 23 which was fairly straightforward once I got down to it, and still the game locks up HARD as soon as a Vehicle touches a RigidShape, to the point I need to restart my window manager. Running it in a debugger is only slightly better, I surmise that I get into an infinite loop somewhere. I'm having my artist go through the collision mesh on the test RigidShape, but I don't have a lot of hope of him finding anything.DALO, wish I could help you, but my game doesn't use any DIF objects. Vehicles+Torque = Pain in the Butt, it turns out.
One major purchase decision regarding Torque3D for me will be whether or not this ever got fixed.
#107
07/07/2009 (2:52 pm)
Unfortunately there's no 100% fix without delving into the source (let me know if you find otherwise). I've found that keeping the collision meshes less dense and simpler will reduce crashing in the server.
#108
07/09/2009 (2:52 am)
@ross : Do the collision fixes work with tgea 1.8.1 . Have u tested any ?
#109
Please email at imaginationseven7@yahoo.com
also do you know if you have to us 3dmax or could you us softimage
thanks for your time
08/31/2009 (11:25 pm)
Ross sorry to bother you, this is off the topic but I was wondering how far you are on the T3D breakable stuff? Please email at imaginationseven7@yahoo.com
also do you know if you have to us 3dmax or could you us softimage
thanks for your time
#110
01/02/2010 (10:45 pm)
Hey guys, does anyone know if this collision algorithm would be an improvement on what we have now, and/or if there have been improved/faster versions since it was first published. http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.19.5430
#111
I'd definitely drop the bucks for it just for that.
02/09/2010 (7:06 pm)
Anybody know if this is resolved at all in the latest and greatest T3D?I'd definitely drop the bucks for it just for that.
#112
02/09/2010 (7:16 pm)
From what i've read they have PLANS for Bullet + T3D, but not in the actual release. I could be wrong though.
#113
02/09/2010 (11:14 pm)
But I wonder how much of the underlying collision detection stuff is different. I guess with integrated polysoup that's all been updated.
#114
Eventualy the vehicles will be ported over to either use the physics engine to do collision sweeps or maybe fully physics driven.
We also plan on adding cloth, ragdolls, a new breakable shape framework, and support for Havok. The idea is to have a basic level of Torque physics primitives which are abstracted and work across multiple physics engines.
02/10/2010 (12:00 am)
Some initial Bullet support is in T3D 1.1 beta 1, but its basically just static collision geometry, player controller, and a new physics object similar to RigidShape.Eventualy the vehicles will be ported over to either use the physics engine to do collision sweeps or maybe fully physics driven.
We also plan on adding cloth, ragdolls, a new breakable shape framework, and support for Havok. The idea is to have a basic level of Torque physics primitives which are abstracted and work across multiple physics engines.
#115
I guess then the answer to my question would be "No, but only because we have some much better stuff planned", eh?
02/10/2010 (1:20 am)
@Tom: That sounds awesome!I guess then the answer to my question would be "No, but only because we have some much better stuff planned", eh?
Torque Owner Justin Chiu
Default Studio Name