Game Development Community

Damage Overlay - How Do I Link It To Health? Please Help!

by ITT019GreenBay (#0006) · in Torque Game Engine · 01/18/2009 (11:18 am) · 30 replies

I've searched through the forums over and over again and I can't seem to find anything like this.

What I'm trying to do is:
When the player takes damage their 'vision' becomes more red and obscured. Many games do this for damage instead of using a 'health bar'.

Currently I have
-The image on the GUI (but it's 100% visible)
-The health regenerating itself over time

So is there anyone out there that is able to help me figure out how to link "Player Health" to a GuiBitmap image opacity/alpha?
Page«First 1 2 Next»
#21
02/12/2009 (5:32 pm)
@ deepscratch -

Quote:
will only be able to try it out in 2 more days,( I'm busy generating a 128000X128000 texture in L3DT for
a 131kmX131km terrain, been generating for 2 days already, takes 4 days and my other pc doesnt have
torque installed on it)

Ah yes... this makes me nostalgic for the old days when I was experimenting with ray tracing in POV-Ray on an old 386 PC (which didn't even have a math coprocessor). Nowadays we have faster and infinitely more powerful computers and what do we do? We just keep installing more intensive software to max out that potential. :-)

Of course, today we can build worlds that can actually be gone into (well, virtually) and walked around in instead of just looked at from "outside" so I guess that's progress.

#22
02/13/2009 (12:45 am)
excellent!! works a treat in tgea 1.7.1
thanks Charles.
now to work out how to get random images to appear...
#23
04/05/2009 (10:22 am)
Works great on TGE 1.5.2 with only one minor error.....

When the player dies in game and respawns, the Overlaytex is still on
screen and doesn't reset back, even with my health back to 100%....

I have to get injuried once for my overlay pic to reset.........

Thanxs in advance for any help or fix..............

Opps Never mind, I fixed myself, I think?????

What I did was, added the

// Initially make the overlay completely transparent
DamageOverlay.setGlobalAlpha(0.0);

to the bottom of my GameConnection::createPlayer function, in the
starter.fps/server/scripts/game.cs file, so now when my player respawns,
the Overlay image reset its self just like when we first start the game.

If I'm wrong about this or where to reset it, Please by all means, let
me know...............Highground Out
#24
04/05/2009 (11:07 am)
This sounds like a good place to do it. If this is the only place where Players are created, then I don't think you should see any problems.
#25
04/05/2009 (3:14 pm)
I love the blood overlay that splats up on my screen but I have one question.......How can I have like say 5 different overlays to randomly popup when I take damage???? The same Overlay for damage would get old quick I would think..........Thanxs in advance for any help on this idea.............Highground
#26
04/06/2009 (3:18 pm)
Quote:
>What I did was, added the
>// Initially make the overlay completely transparent
>DamageOverlay.setGlobalAlpha(0.0);
>to the bottom of my GameConnection::createPlayer function, in the
>starter.fps/server/scripts/game.cs file, so now when my player respawns,
>the Overlay image reset its self just like when we first start the game.

@Highground:

Oops. Yep, you're right. Never noticed this initially, as during testing I never actually let the player object die, just raised and lowered his health.

Your solution will work fine, as long as you are working strictly with a single player game (where the client and server are both on the same machine anyway). However, in case you want it work over a network for multiplayer purposes, it might be better to add this to the end of GameConnection::createPlayer instead...

commandToClient(%this, 'AdjustOverlay', 0.0);

... I'm pretty sure the function GameConnection:createPlayer is executed by the server, while adjustments to the GUI are of course the responsibility of the client, so letting it be handled through the client command makes sure it works for both single and multi-player modes.

As for making it swap between multiple overlays... this may work:

The "bitmap" property of the DamageOverlay can also be set dynamically from the client side (as well as just the transparency). So if you set up an array of 5 image names and use a random number function to select one every time the image alpha drops to zero (so the change of image is handled while the player can't see the overlay), you might be able to do something like you described. (But don't forget that once game play has started, you have to use full path names to the image files).

Something like...

// Set these up somewhere where they will execute before the game starts
// Say, for instance, at the top of game.cs (Note the use of full paths)
$DOImage[1] = "starter.fps/client/UI/overlay1.png";
$DOImage[2] = "starter.fps/client/UI/overlay2.png";
$DOImage[3] = "starter.fps/client/UI/overlay3.png";
$DOImage[4] = "starter.fps/client/UI/overlay4.png";
$DOImage[5] = "starter.fps/client/UI/overlay5.png";

Then, maybe change the client command as follows...

function clientCmdAdjustOverlay(%newAlpha)
{
     DamageOverlay.setGlobalAlpha(%newAlpha);
     if (%newAlpha == 0.0)
     {
        %r = getRandom(1,5);
        DamageOverlay.bitmap = $DOImage[%r];
     }
}
#27
04/07/2009 (12:04 am)
Whoops... good catch, Charles, I didn't think about that.
#28
04/07/2009 (6:15 am)
Charles, That works great....Now I have different blood......coooooolll
#29
04/07/2009 (4:31 pm)
Here's a quick question......How could I tie sound to this, so that it fades with the overlay???? Say like a heart beat or something......
#30
04/08/2009 (5:50 am)
Hi Donnie,
You may play a heartbeat in a channel add keep a thread (a schedule task) running. This thread should check the current health level and depending on that increase the heartbeat playback speed and its volume so the more damage the plaer gets, the heartbeat will be faster and louder.
You may also add some variants like reducing the simulation speed and general sounds so it gets like in the movies when a bomb explodes near the guy and he cant hear anything and sees all in slow motion.

Luck!
Guimo
Page«First 1 2 Next»