Vehicle speed bug
by Howard Dortch · in Torque Game Engine · 09/15/2007 (9:01 am) · 3 replies
If you set the max speed of a vehicle to something like 5, call accelerate(1) and just let it run it will gain speed over time. Anyone know how to fix this?
I am trying to set the speed of a vehicle from script.
I am trying to set the speed of a vehicle from script.
#2
However, as you coded the change here, this is a big change to how it acts as you are approaching the maximum speed. (The last line of your if block gives max torque at all speeds up until you hit the other branch.)
Ground vehicles typically have a maximum engine power that is roughly constant. (Gears make this a little more complex too, but let's ignore that here.) Because power = force times speed, the force available from the constant power engine reduces as the speed increases (this means that in the real world you tend to accelerate slower and slower as you get faster until you get to your maximum speed and the accelerating force has dropped enough to become equal to all the retarding forces.)
The original equation models this normal vehicle behavior. Removing it during acceleration may make a car seem wierd (you accelerate up and up and then BAM - seem to hit a wall), instead of the speed slowly topping out as one might expect from normal driver experience.
You might try just using: wheel->torqueScale = 1.0f - (mFabs(wheel->avel) / maxAvel);
always which would add in your change but retain the more realistic acceleration behavior.
09/15/2007 (8:26 pm)
I have no real issue with allowing the torquescale to drop slightly below zero near max speed (it likely works OK - I haven't tested it myself though.) One thing to watch out for though is that this may put in more high frequency oscillations because of how the tire springs work. However, as you coded the change here, this is a big change to how it acts as you are approaching the maximum speed. (The last line of your if block gives max torque at all speeds up until you hit the other branch.)
Ground vehicles typically have a maximum engine power that is roughly constant. (Gears make this a little more complex too, but let's ignore that here.) Because power = force times speed, the force available from the constant power engine reduces as the speed increases (this means that in the real world you tend to accelerate slower and slower as you get faster until you get to your maximum speed and the accelerating force has dropped enough to become equal to all the retarding forces.)
The original equation models this normal vehicle behavior. Removing it during acceleration may make a car seem wierd (you accelerate up and up and then BAM - seem to hit a wall), instead of the speed slowly topping out as one might expect from normal driver experience.
You might try just using: wheel->torqueScale = 1.0f - (mFabs(wheel->avel) / maxAvel);
always which would add in your change but retain the more realistic acceleration behavior.
#3
My primary goal is to have the user set a speed from 0 to 5 and have the vehicle maintain that exact speed.
09/16/2007 (6:28 am)
Thanks Matt I'll mess with it more. The stock formula just allowed the speed to creep up over time and I can't have that in this app.My primary goal is to have the user set a speed from 0 to 5 and have the vehicle maintain that exact speed.
Torque 3D Owner Howard Dortch
Default Studio Name
wheel->torqueScale = (mFabs(wheel->avel) > maxAvel) ? 0 :
1 - (mFabs(wheel->avel) / maxAvel);
if the velocity is greater than max, wouldn't you want to make torqueScale < 0 ?
I changed it to this and it maintains a steady speed.
if(mFabs(wheel->avel) > maxAvel)
wheel->torqueScale = 1.0f - (mFabs(wheel->avel) / maxAvel);
else
wheel->torqueScale = 1.0;