Floating Damage Display

You've probably played other games where you attack an enemy and any damage you deal is shown floating up from the victim's head and disappearing. It's a simple, but effective way to indicate the damage dealt or received.
First, we need to determine when the character is getting damaged. If we look in the Combat folder, then Combat Events, there's a tile called [hit by attack] that looks like the solution to our problem. However, this tile only determines when the character is hit by a melee or projectile attack, not when the character has taken damage. Damage can come in forms other than melee or projectile attacks, like an area-of-effect (AOE) spell, or a damage-over-time (DOT) effect. This type of damage will not register with the [hit by attack]. If we want to report all damage, we'll have to find a different way.
Fortunately, there is a way. What does the [damage] tile do? According to the tile's long description, it removes a set amount of health from an object. So if we can detect when a character's health decreases, we are effectively detecting when it's receiving damage. We do this by using [health][decreased].
Now that we've determined that the character has taken damage, the next step is to determine how much damage was received. We can do that by saving the current health of the character, then comparing that with the character's health after they've taken damage:
IwDWXvWhat do we do with this information now? Display it in a cool, animated, floating up kind of way:
no9FXJWhoa! that line is long! Let's break it down:
[display][negative][Damage Taken] will display the value of Damage Taken with a minus sign in front. The [negative] is optional, but I use it just in case I want to show heals or health gains later and I want them to appear different. You might be tempted to differentiate damage and heals by just displaying them in different colors, but there are a lot of people in the world that are color blind and there's a good chance that they might play your game and get confused.
The next part is the really interesting bit. [at position][head][position][plus][world up][multiplied by][timer ratio complete]. We start at the position of the head socket, then add the world up vector multiplied by the amount of time that's passed on the timer.
The [timer ratio complete] tile will be a number between 0.0 and 1.0 that indicates the percentage of time that has passed since the timer started. Each frame, this number is increased by a little bit (1/30th of a second or 0.0333333, if the timer is for 1 second), so the final position starts at the head position--timer ratio complete is 0.0--and moves up until it's 1 unit above the head positon--timer ratio complete is 1.0, multiplied by world up, is 1 unit above. If you increase the value of the timer, the text will appear to move up to its final position more slowly because it has more time to get from the head position to 1 unit above the head position. Decrease the timer value and the text floats up more quickly.
The rest of the line [medium font][red] is just for 'flavor' and can be changed to your preference.
Now we have a cool floating damage indicator, but we can make it better. What if the character takes more damage before the current damage amount is finished displaying? We'll have to track more than one value for Damage Taken. Let's track up to three amounts. You can more, if you need them. Also, let's make it easier to change the 'speed' of the floating text by using a variable for the timer. Lastly, let's make it easier to re-use in other characters by putting the kode in a logic cube so we can add it the character's main brain:
KXJoxTWe've defined three values: dmg1, dmg2, dmg3 to track the last three times the character has taken damage. Each time the character takes damage, it checks if one of the values is not currently being used and sets the current damage taken value to it. If all three are already used, it overwrites the first value (because it's the oldest and is probably close to finishing, anyway). If you find that the values are getting overwritten too often, add a dmg4 and maybe a dmg5.
Then we check each of the dmgx values and display them. For a little more variety, I changed the direction of dmg2 to move diagonally up and to the right and the direction of dmg3 to up and to the left.
Now our little Floating Damage Text logic cube is finished. Add it to any character to have them display floating damage text:
wwAgboI set the Dmg Display Time to 2 seconds so that it's easier to see all three values float up when attacking this character.