Ouch! Where'd that come from? Directional Hit Indicators
by Michael Hall · 07/21/2011 (2:22 pm) · 3 comments
Got an email today requesting the directional damage indicator method I alluded to back in my Improved PlayDeathAnimation Resource. Just like I did there I give you this disclaimer: Be aware that getDamageLocation() can fail on occasion as well as return incorrect location information. That is a long-standing problem with the "best guess" damage coverage calculation that Torque uses. This is probably why in the player Damage() method %location is hardcoded to "body".
You'll need the graphics for the hit direction indicators, get them at eb's Unofficial Torque Public File System. Exctract the zip file such that the images are located in the YOURGAME: "art/gui/playHud/" directory
Pay attention to the image filenames. A specific naming scheme is used so as to make it easy to use the return from getDamageLocation().
Add 2 bitmap controls to the playGui (before the closing brace): one for a headshot indicator, one for direction.
This won't do anything yet, just make sure that both have visiblity toggle off if you create them through the GUI Editor. Time to add the script code.
Server-side we add to the player Damage() method to get the damageLocation in order to determine the direction the shot came from. This then sends a call to client-side code to push the relevant graphic image to the HUD.
Inside of player.cs find PlayerData::damage() -- or Armor::damage() if you're making using of the scripted sub class functionality -- and change
Now for the client-side code, in client.cs add the following.
The trick I used here is to append the %region parameter (returned from getDamageLocation()) as part of the filename of the graphic to display. You'll notice that this only accounts for diagonal quadrants. But it would be a simple exercise to use some if/else/switch logic to figure out the cardinal directions. Furthermore, since the head is split into more regions than the legs or the torso, and has a different naming structure, I opted for a headshot indicator for simplicity -- in my game if you get shot in the head (unarmored) you're either dead or struck too dumb to even wonder what direction that shot came from. Feel free to modify if more directionality is desired.
You'll need the graphics for the hit direction indicators, get them at eb's Unofficial Torque Public File System. Exctract the zip file such that the images are located in the YOURGAME: "art/gui/playHud/" directory
Pay attention to the image filenames. A specific naming scheme is used so as to make it easy to use the return from getDamageLocation().
Add 2 bitmap controls to the playGui (before the closing brace): one for a headshot indicator, one for direction.
new GuiBitmapCtrl(HeadshotIndicator)
{
bitmap = "art/gui/playHud/headshot.png";
wrap = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "center";
VertSizing = "center";
position = "0 0";
Extent = "1024 768";
MinExtent = "8 8";
canSave = "1";
Visible = "0";
tooltipprofile = "GuiToolTipProfile";
hovertime = "1000";
canSaveDynamicFields = "0";
};
new GuiBitmapCtrl(HitDirection)
{
bitmap = "art/gui/playHud/hit.png";
wrap = "0";
isContainer = "0";
Profile = "GuiDefaultProfile";
HorizSizing = "center";
VertSizing = "center";
position = "480 352";
Extent = "64 64";
MinExtent = "8 8";
canSave = "1";
Visible = "0";
tooltipprofile = "GuiToolTipProfile";
hovertime = "1000";
canSaveDynamicFields = "0";
};This won't do anything yet, just make sure that both have visiblity toggle off if you create them through the GUI Editor. Time to add the script code.
Server-side we add to the player Damage() method to get the damageLocation in order to determine the direction the shot came from. This then sends a call to client-side code to push the relevant graphic image to the HUD.
Inside of player.cs find PlayerData::damage() -- or Armor::damage() if you're making using of the scripted sub class functionality -- and change
%location = "Body";To:
// Locational damage, damage amount modifiers - this is NOT true locational
// damage, but only a "best guess" based on a hitbox percentage calculation
// done by the engine.
%location = %obj.getDamageLocation(%position);
%bodyPart = getWord(%location, 0);
%region = getWord(%location, 1);
//echo("\c4DAMAGELOCATION: bodyPart = "@ %bodyPart @" || REGION = "@ %region);
// BODYPARTS: HEAD | TORSO | LEGS
// REGION (legs/Torso): front_left | front_right | back_left | back_right
// REGION (head): left_back | left_middle | left_front
// middle_back | middle_middle | middle_front
// right_back | right_middle | right_front
if (%damageType !$= "MissionAreaDamage")
{
if (%bodyPart !$= "head")
commandToClient(%obj.client, 'DisplayHitDirection', %region);
else
commandToClient(%obj.client, 'DisplayHeadshotIndicator');
}You'll notice the check for MissionAreaDamage. I left this in since I am intending another Resource that deals with the MissionArea. Looking at my old scripts I see a possible 4-5 Resources just out of damage() alone :) But in any case consider this an example of how to exclude a damageType, as well as recurring or area effect damage, from displaying a hit direction.Now for the client-side code, in client.cs add the following.
// ----------------------------------------------------------------------------
// Headshot indicator
// ----------------------------------------------------------------------------
// Show the onscreen Headshot Indicator, then schedule it being hidden in 500ms.
function ClientCmdDisplayHeadshotIndicator()
{
HeadshotIndicator.setVisible(true);
schedule(500, 0, "HideHeadshotIndicator");
}
function HideHeadshotIndicator()
{
HeadshotIndicator.setVisible(false);
}
// ----------------------------------------------------------------------------
// Hit indicator
// ----------------------------------------------------------------------------
// Show the onscreen Hit Direction, then hide it in 500ms.
// BODYPARTS: HEAD | TORSO | LEGS
// REGION (legs/Torso): front_left | front_right | back_left | back_right
// REGION (head): left_back | left_middle | left front
// middle_back | middle_middle | middle_front
// right_back | right_middle | right_front
// We're only dealing with the legs & torso region(s) for the hit direction
// indicator in order to keep things simple and easy
function ClientCmdDisplayHitDirection(%region)
{
//echo("\c4ClientCmd DisplayHitDirection -- REGION = "@ %region);
HitDirection.setBitmap("art/gui/playHud/hit_"@ %region);
HitDirection.setVisible(true);
schedule(500, 0, "HideHitDirection");
}
function HideHitDirection()
{
HitDirection.setVisible(false);
}The trick I used here is to append the %region parameter (returned from getDamageLocation()) as part of the filename of the graphic to display. You'll notice that this only accounts for diagonal quadrants. But it would be a simple exercise to use some if/else/switch logic to figure out the cardinal directions. Furthermore, since the head is split into more regions than the legs or the torso, and has a different naming structure, I opted for a headshot indicator for simplicity -- in my game if you get shot in the head (unarmored) you're either dead or struck too dumb to even wonder what direction that shot came from. Feel free to modify if more directionality is desired.
About the author
Been dabbling with game-programming since the age of 10 when I got my first computer, a Commodore. Got serious about game-development after modding Tribes for several years. Doesn't sleep much. Drinks rum. Teaches guitar. Plays cello.
#2
10/31/2011 (11:09 pm)
link to download the bitmap appears broken
#3
@all: If the link to eb's site continues to be flaky I'll find some other alternative host. For the interim, if the link doesn't work simply email me and I'll send you the example art.
11/01/2011 (9:23 am)
@Jeff: the link appears to be working again. @all: If the link to eb's site continues to be flaky I'll find some other alternative host. For the interim, if the link doesn't work simply email me and I'll send you the example art.

Torque Owner Robert Fritzen
Phantom Games Development
I just wrote my own the other day for my FPS resources. this looks nice though.