Game Development Community

Flying vehicle ground collsion crashes engine

by Andy Hawkins · in Torque Game Engine · 04/25/2008 (5:40 am) · 1 replies

I would like to get the staff to resolve this if possible, as it seems this has never been fixed. In a flying vehicle if you hit the ground really hard the engine freezes and then crashes.

As I'm releasing BRAVE in a few days I can't have this happen. How can this be fixed or worked around please?

#1
04/25/2008 (10:09 pm)
There is a quick and dirty hack to fix a whole classes of these freezes. The root cause is that the Rigid Shape collision solver can't resolve the collision with the ground and so gets stuck in an infinite loop. The fix is to put a max retry count on the loop so you can break out. You may get a situation where your vehicle will appear to go slightly into the ground, but unless its going really, really fast, it still shouldn't break through. You can mess with the integration and collisionTol variables in the datablock to tweak after implementing this fix...

-----FIX-----

In vehicle.cc, after
bool Vehicle::resolveCollision(Rigid&  ns,CollisionList& cList)
{
   // Apply impulses to resolve collision
   bool colliding, collided = false;

insert

U32 collisionCount = 0;

After

// Apply impulses to the rigid body to keep it from
// penetrating the surface.
 ns.resolveCollision(cList.collision[i].point,
    cList.collision[i].normal);
colliding = collided  = true;

Insert
collisionCount++;

Replace
} while (colliding)

with

} while (colliding && collisionCount < 64);

NOTE: you can increase or decrease the max collision count to suit your needs. You may even want to make it a field in VehicleData if you need this for different objects. Obviously this is a hack, but after I implemented it all the nasty crashes and freeze I had with vehicle collision went away. There may be other similar implementations of this fix in the forums and I know the Sickhead Games guys have done some work on collision response as well (there is a nice long post somewhere in this Forum with all their code).

I hope that works for you!