Game Development Community

TGE 1.4 wheeledvehicle bug and fix #2

by Duncan Gray · in Torque Game Engine · 11/26/2005 (3:06 pm) · 9 replies

This bug is only present in version 1.4

In updateForces() at line 754 is the following bit of code, new to 1.4
// Calculate vertical load for friction.  Divide up the spring
   // forces across all the wheels that are in contact with
   // the ground.
   U32 contactCount = 0;
   F32 verticalLoad = 0;
   for (Wheel* wheel = mWheel; wheel < wend; wheel++) 
   {
      if (wheel->tire && wheel->spring && wheel->surface.contact) 
      {
         verticalLoad += wheel->spring->force * (1 - wheel->extension);
         contactCount++;
      }
   }
   if (contactCount)
      verticalLoad /= contactCount;

The problem is the verticalLoad results never get used because at line 849 we have
// Vertical load on the tire
         verticalLoad = spring + damping + antiSway;

which effectively overwrites the previous calculation result.

Perhaps it should read:

verticalLoad += spring + damping + antiSway;

#1
12/24/2005 (11:44 am)
For future reference, this code is located in game/vehicles/wheeledVehicle.cc
#2
01/21/2007 (11:03 pm)
Thank u tis bug is not fixed in 1.5
#3
01/21/2007 (11:51 pm)
I don't understand how verticalLoad works in this case. Why would it add the loads on the tires twice? I don't know if this is really a bug or not.
#4
01/22/2007 (2:37 am)
Tom: but surely Duncan's observation that the initial calculation of verticalLoad is redundant is correct? Seems like a pointless waste of CPU..?
#5
01/22/2007 (3:11 am)
Right i do see that the initial calculation is pointless as the code is now.. it does nothing. That makes me more curious about what the right fix is. Should it maybe be removed? I'm not sure, but i'm looking into it now.
#6
01/22/2007 (12:12 pm)
Version 1.3 never had that initial calculation, it was added in 1.4 and thats when I noticed that the newly added code seemed to be flawed. Perhaps the staff member that added the code could shed some light on its intended use.
#7
01/22/2007 (12:49 pm)
I traded an email with Tim Gift. He said that the first calculation was a bit of a hack and that he never got it to work correctly. The second per-tire calculation... the one that is in there now... is the one he recommends is kept.

So mystery solved... that first loop can be totally removed.
#8
01/23/2007 (6:55 pm)
Thanks for this guys. Just makes my code a little bit cleaner. ;)
#9
03/11/2007 (10:18 pm)
Then, "So mystery solved... that first loop can be totally removed."
how is the correct code version of the fix?, you can post it?
thanks.