Nitro with vehicle
by Alejandro Lopez · in General Discussion · 09/05/2008 (4:00 pm) · 7 replies
I am making a racing car game , and i want to make a nitro , for the car, or turbo, but i see that doesnt exits in the vehicle functions . i was trying with a applyImpulse, but its not the best way.
is there any way to accelerate the engine ?
is there any way to accelerate the engine ?
#2
09/06/2008 (9:05 am)
I was thinking that adding some impulse , maybe was not the correct way, if we look a real car, its has a engine , and if i add some impulse the engine will not revolutioned or rotate ( i dont know was the word in English ) its will be just add an impulse, and it would see strange and uncontroleable. Maybe if we know how works the engine of the vehicledata, we can thinks how to do that. i think the engine works with forces, but , whats the purpose of "engine" and how can i add force to the engine, (and not to the vehicle).
#3
First, look in vehicle.cc, under the updateMove function, it checks the trigger[3] value nd sets the mJetting flag to true. Then it computes the energy drain. You can change these in the corresponding vehicle datablocks in script. This function doesn't do the actual nitro thing, just computes the energy drain as a result of the nitro.
The wheeledVehicle class which derives from the Vehicle class does the actual nitro (jetting) thingy. Look in WheeledVehicle::updateForces() and you'll see two lines:
This one increases the engine Torque being applied. Then the second one:
applies a force, which might be analogous to applying an impulse. Only in this case, the impulse is in the direction of the already existent force - just a scaling actually.
So, basically, all you need to do is:
1) Make sure you have the datablock variables defined correctly (jet energy drain, minimum energy, jet force)
2) In your OnAdd function, which I'm assuming is like : WheeledVehicleData::onAdd(%this, %obj) just add the following lines
This will setup the required energy levels for the corresponding datablock.
3) Now, on client-side, bind a function to the keyboard (say the n key or something) and in the callback function, increment the $mvTriggerCount variable.
Thats all to it!
You can also use a separate sound for jetting, you'll have to declare an audio profile in script and set the corresponding sound field in the datablock.
Hope it helps!
09/06/2008 (10:54 am)
This feature is already implemented, so to speak. All you have to do is use the 3rd trigger (mvTrigger3) to set it off. Let me explain how exactly I got it working.First, look in vehicle.cc, under the updateMove function, it checks the trigger[3] value nd sets the mJetting flag to true. Then it computes the energy drain. You can change these in the corresponding vehicle datablocks in script. This function doesn't do the actual nitro thing, just computes the energy drain as a result of the nitro.
The wheeledVehicle class which derives from the Vehicle class does the actual nitro (jetting) thingy. Look in WheeledVehicle::updateForces() and you'll see two lines:
if (mThrottle > 0 && mJetting)
engineTorque *= 2;This one increases the engine Torque being applied. Then the second one:
if (mJetting)
mRigid.force += by * mDataBlock->jetForce; applies a force, which might be analogous to applying an impulse. Only in this case, the impulse is in the direction of the already existent force - just a scaling actually.
So, basically, all you need to do is:
1) Make sure you have the datablock variables defined correctly (jet energy drain, minimum energy, jet force)
2) In your OnAdd function, which I'm assuming is like : WheeledVehicleData::onAdd(%this, %obj) just add the following lines
%obj.setEnergyLevel(%this.MaxEnergy); %obj.setRechargeRate(%this.rechargeRate);
This will setup the required energy levels for the corresponding datablock.
3) Now, on client-side, bind a function to the keyboard (say the n key or something) and in the callback function, increment the $mvTriggerCount variable.
Thats all to it!
You can also use a separate sound for jetting, you'll have to declare an audio profile in script and set the corresponding sound field in the datablock.
Hope it helps!
#4
09/06/2008 (10:54 am)
Any forces added to the "engine" would only make the car uncontrollable. You would have to apply a force to the whole vehicle. Make sure to add down force with forward force to make the vehicle somewhat controllable. If you look at how nitro race cars work, they loose some control as well. Adding nitro on a curve wouldn't be a good idea, but on a straightaway, the added torque would propell you forward.
#5
09/07/2008 (8:09 am)
I assumed that you wanted to have the car shoot forward in an unrealistic way. If you just want to give more engine power, then you have to be restrained about how much you add (as people have said) and be concerned not to add too much to make the car uncontrollable for people without joystick type throttle controllers.
#6
what do you mean increment the $mvTriggerCount variable? Can you shed some light on this? I am interested in making this work.
06/25/2009 (7:52 pm)
@Koushik or anyone else: what do you mean increment the $mvTriggerCount variable? Can you shed some light on this? I am interested in making this work.
#7
EDIT: I believe it's trigger3 anyway.
06/26/2009 (10:59 pm)
moveMap.bind(mouse, button1, vehBoost);
function vehBoost(%val)
{
$mvTriggerCount3++;
} And make sure you have your vehicle datablock & onAdd() function setup as described by Koushik.EDIT: I believe it's trigger3 anyway.
Torque 3D Owner Matthew Jessick
The reason you don't want to do it via just making the engine more powerful is that pretty soon as you crank up the power, you will start to spin the rear tires. As soon as that happens, the car will be unstable laterally (in yaw). You might have similar problems if you add too large a force, but at least the tires have a chance of maintaining control.