Using Energy as Ammo for Vehicle
by Chad Kilgore · in Torque Game Engine · 02/28/2007 (7:08 am) · 4 replies
How do I limit a vehicle's ammo by its energy? I've looked at www.garagegames.com/mg/forums/result.thread.php?qt=10996 and this modification works perfectly assuming my avatar is PlayerData. I have also modified the GuiHealthBarHud (www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=2856) so that vehicles have health and energy. But the vehicle's energy is never changed when I shoot. Any ideas?
#2
02/28/2007 (8:10 am)
I'm not sure exactly what a vehicle's 'energy' means, or even what you want it to mean. I would guess you want the engine to lose power when you fire a gun? Go and look in wheeledVehicle.cc and you'll easily find the place where engineTorque (from the datablock) is directly used to power the wheels. A quick and easy hack could be used to put an extra factor in there so that 'energy' affected this engineTorque calculation.
#3
I'm pretty sure what he means is he wants the vehicle to have energy based weapons (lasers, etc) which would have a limited pool of energy as ammo, much like the player has. Not necessarily affecting the vehicle's operation itself, though not bad gameplay idea now that I think about it.
@Chad
I agree with Martin that the problem is most likely related to the onFire code. Make sure you're accessing the vehicle's energy and not the player's.
02/28/2007 (8:19 am)
@SamI'm pretty sure what he means is he wants the vehicle to have energy based weapons (lasers, etc) which would have a limited pool of energy as ammo, much like the player has. Not necessarily affecting the vehicle's operation itself, though not bad gameplay idea now that I think about it.
@Chad
I agree with Martin that the problem is most likely related to the onFire code. Make sure you're accessing the vehicle's energy and not the player's.
#4
This will add energy weapon and energy to your flyingvehicle or flyer
// datablock settings
usesEnergy = true;
minEnergy = 150;
//firing state energy used per second
stateEnergyDrain[3] = 150;
And you must have this in the bottom of your vehicle script.
function Drone::onAdd(%this,%obj)
{
%obj.setEnergyLevel(%this.maxEnergy);
%obj.setRechargeRate(%this.rechargeRate);
}
03/27/2007 (11:48 am)
Yes Chad, you must set the following in your weapon script.This will add energy weapon and energy to your flyingvehicle or flyer
// datablock settings
usesEnergy = true;
minEnergy = 150;
//firing state energy used per second
stateEnergyDrain[3] = 150;
And you must have this in the bottom of your vehicle script.
function Drone::onAdd(%this,%obj)
{
%obj.setEnergyLevel(%this.maxEnergy);
%obj.setRechargeRate(%this.rechargeRate);
}
Torque Owner Martin Schultz
%player.setEnergyLevel( %player.getEnergyLevel() - 20); // 20 is the amount to suck at each fire