Game Development Community

Race games - collision for fast moving vehicles

by Tcangussu · in Torque Game Engine · 11/23/2006 (1:45 pm) · 6 replies

Hi everybody!

I'm currently developing a space ship race game. I implemented ships with third person camera using FlyingVehicle class.
When two fast moving ships collide with each other, I have the visual impression that the collision occurs before when it should. Collisions happens when my adversary is coming from behind and almost touching my back. I don't see the meshes actually colliding, they look very distant from each other. This only happens at high speeds, ex. my speed is 70 and my adversary speed is about 130.

Looking for answers I found this thread www.garagegames.com/mg/forums/result.thread.php?qt=27893, where Manuel Najera talks about collision meshes being streched out at high speed values.

Another thread www.garagegames.com/mg/forums/result.thread.php?qt=7528, pointed me to the Vehicle::updateWorkingCollisionSet() method in vehicle.cc.

This method assumes a maximum velocity for moving objects, and has hardcoded values used to make the object's bounding box bigger. I played around with this method, removing some lines to avoid the bounding box scale, but didn't work.

Does someone knows what I'm talking about? Have someone, who tried to make a race game with Torque (not a rally like starter.racing), experienced this kind of problem?

#1
11/23/2006 (2:43 pm)
Have you tried tweaking the collisionTol and contactTol values in the vehicle datablock? If so, what behavior do you see?
#2
11/26/2006 (3:08 pm)
Thanks for reply!

Low values for contactTol make the engine crash frequently, so I assigned 0.9 to it.
Low values for collisionTol make objects overlap and go deeper inside each other during collisions.
It could be the answer for my problem, so I assigned 0.1 to it.
Even doing this, a strange collision happens only in this situation: when two ships have the same direction, with one of them right behind the other and with a higher velocity. The camera behavior is also strange.
I was thinking about record a video to explain better what I mean.

I dont know for sure whether it has something to do with high speeds or not.
Tomorrow I'll do some investigations (putting printf()'s at collision code) and tell what I get.
#3
11/28/2006 (8:31 am)
I've solved this issue. It wasn't related to high velocities nor vehicle collision.

The problem was the camera.
The code at Vehicle::getCameraTransform() that makes camera stay out of objects it hits was causing the annoyance I've told, when an enemy vehicle was between the camera and my vehicle avatar.
Also, with low FOV values I could see better that the two vehicles were really touching each other during collision.

So, that's it. Torque physics rules!!!
#4
11/28/2006 (8:48 am)
So did you change the code? If so I would like to try out what you did.
#5
11/28/2006 (8:48 am)
Low values for contactTol should not make the engine crash, but freeze.

Glad you got it working.
#6
11/29/2006 (8:36 am)
@Ron
Here is what I've done to disable camera moving when colliding with other objects:

file: vehicle.cc
method: void Vehicle::getCameraTransform(F32* pos,MatrixF* mat)

Replace this:
// Make sure we don't hit ourself...
   disableCollision();
   if (isMounted())
      getObjectMount()->disableCollision();

   // Cast the ray into the container database to see if we're going
   // to hit anything.
   RayInfo collision;
   Point3F ep = sp + vec + offset + mCameraOffset;
   if (mContainer->castRay(sp, ep,
         ~(WaterObjectType | GameBaseObjectType | DefaultObjectType),
         &collision) == true) {

      // Shift the collision point back a little to try and
      // avoid clipping against the front camera plane.
      F32 t = collision.t - (-mDot(vec, collision.normal) / vec.len()) * 0.1;
      if (t > 0.0f)
         ep = sp + offset + mCameraOffset + (vec * t);
      else
         eye.getColumn(3,&ep);
   }
   mat->setColumn(3,ep);

   // Re-enable our collision.
   if (isMounted())
      getObjectMount()->enableCollision();
   enableCollision();

with this:
Point3F ep = sp + vec + offset + mCameraOffset;
   mat->setColumn(3,ep);


Alternatively, you could wish this feature enabled just for terrain collision:
Just replace this:
if (mContainer->castRay(sp, ep,
         ~(WaterObjectType | GameBaseObjectType | DefaultObjectType),
         &collision) == true) {

with this:
if (mContainer->castRay( sp, ep, TerrainObjectType,
         &collision) == true) {