Game Development Community

dev|Pro Game Development Curriculum

Vehicle Health/Energy Bar

by Anthony Rosenbaum · 06/18/2002 (2:22 pm) · 13 comments

Download Code File

Add the attached Gui file to you gui folder, compile, and add to the PlayGui.gui via the Gui Editor. Note you won't see the bars until you are in a vehicle. Also for vehicles with Energy be sure to have somthing like this:
// Energy
    jetForce = 3000;
    minJetEnergy = 30;
    maxEnergy = 200;
    jetEnergyDrain = 2;
    rechargeRate = 0.8;
in the vehicle's DataBlock
AND
in the vehicleType::onAdd(%this, %obj) function you need to set the energy and to set it to recharge. you can do this by adding this :
%obj.setEnergyLevel(%this.MaxEnergy);
      %obj.setRechargeRate(%this.rechargeRate);

Special thanks to Exodus/LabRat both of which I found very helpfull information from their ealier code.

#1
08/06/2002 (1:56 am)
Nice resource, If you want this to work with the race mod:

Remove these lines:

ShapeBase* control = conn->getControlObject();
if (!control || !(control->getType() & PlayerObjectType))
return;

Then Change:

ShapeBase* vehicle = control->getControlObject();
if (!vehicle || !(vehicle->getType() & VehicleObjectType))
return;

To:
ShapeBase* vehicle = conn->getControlObject();
if (!vehicle || !(vehicle->getType() & VehicleObjectType))
return;
#2
08/24/2004 (9:37 pm)
Hey Anthony Rosenbaum, nice resource! I have a question for you and Bruce. I have made the changes that Bruce suggested to get it to work with the racing mod. I made the script additions and when I start my racing mod my car's health bar is still empty? Should it fill up when the race starts? I thought with the change (Bruce's) that I didn't have to mount a player to the vehicle for it to be able to take damage. Or do I still have to? Any help is much appreciated!
#3
07/17/2005 (8:34 pm)
Ignore this - my mistake.
#4
07/30/2005 (3:46 pm)
It's strange, but try as I might, I can't get this to work. All of the code runs and nothing has errors, but the bar itself will not show. Any idea why?
#5
07/30/2005 (4:08 pm)
you need to be in a vehicle to see it
#6
07/30/2005 (8:10 pm)
Okay, so just using the Racing Starter Kit is not enough. Is there any way to disable the requirement of being in a vehicle to see it? I would like to see it pretty much all the time.
#7
12/21/2005 (4:17 pm)
heck, you can use a health bar for anything that supports health, all you have to do is change
ShapeBase* control = conn->getControlObject();
if (!control || !(control->getType() & PlayerObjectType))
return;
to
ShapeBase* control = conn->getControlObject();
if (!control || !(control->getType() & ShapeBaseObjectType))
return;
in the original code
#8
02/15/2006 (11:53 am)
Sorry to pick up on a thread a few weeks old, but what part of original code?

ie. where can I find that bit of code to change?
#9
10/14/2006 (8:22 pm)
I tried it.Cant get it work.
#10
11/23/2006 (11:26 am)
Dan Keller's change needs to be made to guiHealthBarHud.cc in game\fps of the TorqueDemo project. Look for the GuiHealthBarHud::onRender function. It works great in 1.5.

However, I haven't been able to get THIS particular resource to work in 1.5, though it is a few versions old.

-Robert
#11
02/21/2007 (9:10 pm)
#12
10/24/2007 (9:05 pm)
Does anyone have any suggestions for getting this to work in 1.5? I've been fooling around with it and maybe fixed an issue or two, but the gui doesn't seem to do anything in=game once it has been placed. I use vehicles extensively in my project, so I need a health bar for them, or at least change the code so that the player health bar / energy bar changes to show the vehicle health when the player is mounted in a vehicle.
#13
10/24/2007 (10:31 pm)
Sam B. It's not hard to do, just study the script code for vehicle damage. Ok, it's a PITA to do because the stock damage code in Torque is badly broken, and you have to write your own damage system.
I include the scripts with the test version of my game which has vehicle damage w/health bar. www.singularityfps.com . It's still a work in progress, but it does basically work. Do NOT study my player damage code because it's embarrassing (even though it works in my context), but my vehicle damage code is reasonably solid and logical.