Game Development Community

Healthbar manipulation

by Dameeuhn · in Torque 3D Beginner · 12/31/2013 (4:51 am) · 8 replies

So I have a datablock object called "TLogoItem" which is supposed to damage my player when I collide with it. Currently I created a GUI object for the healthbar in the PlayGui.cs file using the following lines,

new GuiHealthBarHud() {
      canSaveDynamicFields = "0";
      Profile = "GuiDefaultProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "0 0";
      Extent = "64 183";
      MinExtent = "8 2";
      canSave = "1";
      Visible = "1";
      hovertime = "1000";
      fillColor = "0 1 0 1";
      frameColor = "1 1 1 1";
      damageFillColor = "1 0 0 1";
      pulseRate = "500";
      pulseThreshold = "0.25";
      flipped = "0";
      showFill = "1";
      showFrame = "1";
      displayEnergy = "0";
   };

I then added a onCollision function to my object "TLogoItem" so that upon collision the health value will decrease. However when I test it out, the object my player collided with gets deleted correctly however my healthbar still looks the same.

function TLogoItem::onCollision(%this, %obj, %col)
{
%obj.applyDamage(100);
%obj.delete();
}
I would like to know how to make it so that when I collide with the TLogoItem object, the healthbar would actually drop so that I can see the fillcolor as well so I know that my health had dropped.

About the author


#1
12/31/2013 (7:19 am)
Quote:
which is supposed to damage my player when I collide with it.

It looks like you're applying damage to the object not the colliding player.
function TLogoItem::onCollision(%this, %obj, %col)
{
   %col.applyDamage(10);//colliding player
   %obj.delete();//this object
}

See if that helps.
#2
12/31/2013 (7:39 am)
Oh yes! I didn't notice that mistake I made. I fixed the code however this time around my HP bar as well as my player disappears after collision. I set the applyDamage value as 10 instead of 100 which was what I set earlier.

What might be the cause of the disappearing hp bar and player?
#3
12/31/2013 (9:10 am)
Death?

Damage is usually applied via the player datablock's own damage function rather than directly.
%col.damage(%sourceObject, %position, %damage, %damageType);
#4
12/31/2013 (9:16 am)
What about the Max health values of the HP bar? I can't seem to find anything within the code which "sets" the health value. Since I used a value, 10, for the applyDamage method I would assume there's a default HP value or something around that I might have overlooked? I would like to modify the health values if possible at all.
#5
12/31/2013 (9:22 am)
It's probably automated in player.cpp on player creation - no point spawning a dead player!
#6
12/31/2013 (9:31 am)
Is there a slightly better hint? Do I have to assign the max health values by myself into the player datablock or somewhere within the onSpawn function? I tried

%col.applyDamage(0.5);

and half of my health block got deducted so I'm assuming the max health value is "1"? I could work with that although if possible changing it to a larger value would definitely make my project easier.
#7
12/31/2013 (10:10 am)
Your max health is in the player datablock - in art/datablocks/player.cs. If you're using Torsion you can use ctrl-shift-f to search the whole project for "maxhealth".

I'm thinking (haven't checked) but if you use a fractional amount of health the system assumes you mean that fraction of the player's health, but I know that if you use an integer value it deducts that number from the player's health. So using 10 would take ten points but using .1 would take 10%....
#8
12/31/2013 (11:21 am)
I am using the TGE 1_5_2 with only the essential files so I might not have what you might be specifying. My player datablock only consists of the onAdd and onRemove functions. I assume this means I need to add the max health values manually?