There are many reasons why a designer may want to get the current value of the player's health. One reason might be to increment damage up to a certain point and no more, or to limit the aggression of opponents based on the health of the player. In this lesson we will log the player's health to an Integer and use that as a multiplier to create a regenerative, but temporary shield. There are many ways to build game mechanics around health, including damage to health based on distance, time, or number of hits. The method here is driven by Kismet. Often anything related to player properties is handled in code by a developer rather than in the level by a gamer, and not surprisingly this exception is fairly scene specific, not a generalized method to effect the player all the time. To provision permanent effects on player health, creating a class is better.
Load the scene from the provided content Packt05_Health_Start.UDK and familiarize yourself with its content. This scene is set in the World Properties to use UTGame as its GameType for PIE. The Kismet is functionally quite complete. There is already a Bot, and already a timer and all the multipliers we need are there to handle the damage. We are only going to look at a mechanism for capturing the value of the player's health.
This scene has the text 'OK' on one side. Once the player presses E to use a Trigger attached to them, the text 'OK' turns to a timer for 10 seconds. This timer marks a shield activation that protects the player from harm. The player is not armed, so to destroy the Bot they must fire off the Trigger opposite the OK once their shield has deactivated and they have visited that location. If they don't, the trigger is not ready and the Bot isn't destroyed, and the player takes damage normally. Open Kismet and note that all the Global Variables for objects in the level are placed already. Likewise, a lot of the basic Kismet we have handled in previous recipes is already set up. You may want to examine the Sub-sequence SpawnBot to see how once spawned it is given a weapon and then commences firing at you and chasing you.
When the player is spawned an enemy Bot is also spawned. A trigger is attached to the player which is the activator for the shield when used. A timer counts down when the trigger is used, during which time the player is shielded. Be sure to check out the Sub-sequences in the demonstration, particularly the Sub-sequence ModifyHealth, which is a test for the amount of damage taken, and a healing result at a certain threshold, until the Delay stops this loop after 10 seconds in the main sequence. The Modify Health actions Mod1, Mod2, and Mod3 do not have a Damage Amount property set, instead drawing on Float Variables assigned as Named Variables that call back and forth to keep the player's health balanced during the shielding period.
The actual math is done in the Sub-sequences Damage Taken Math and AddSubtractMultiply. When the player takes damage, the Damage Taken float value from the event is sent to an integer and logged. An Int Counter tracks the number of times the player has been hit, and logs it as an integer too. These two integers are then blended through an expression (where each action either subtracts the incoming target value, adds to it, or multiplies it by another value). That gives us a XFloatResult and this is compared in the Sub-sequence Modify Health. In the following screenshot Damage Taken Math is on the left and AddSubtractMultiply is on the right:
The shield is not completely impervious. If you stand in a rapid stream of bullets it will inevitably deplete, but if you get a moment to rest your health will bounce all the way back up.
You can review the entire sequence in the provided content Packt_05_Health_DEMO.UDK.
You will notice in the illustration that all the nodes have had their unused nubs hidden, except for the Switch, because of its empty Link 1. To hide nubs, or expose hidden nubs, you can right-click on the node and access the item Hide Unused Connectors or Show All Connectors. If you want to expose a specific hidden nub, try Expose Variable and choose from the list which expands from it.
The PostProcess effect and the light shafts that are toggled when we trigger the shield are discussed in detail in Chapter 8, Then There Was Light!
3.134.103.74