Player Health Manager
At the root of a lot of aspects of a survival game is the player’s health value. Used to control their life/death state, and to give important to systems such as hunger and thirst, the health system included in the MSGT is simple and effective. Included with it is a falling damage system that allows you to limit the players ability to survival large falls.
Setup
Requirements
No special requirements needed. Though for certain functionality, such as detection of shots fired using the default MSGT weapon system, both the player controller and player character blueprints will need to have their interfaces assigned correctly. This is already done in the included SurvivalController (which has the blueprint interface BPInt_Controller assigned to it) and SurvivalCharacter (which has the blueprint interface BPInt_Character assigned to it). These interfaces simply allow easier and more reliable communication between various pieces of logic.
Initial Setup
After adding the C_Manager-Health component to your player controller, the component merely needs to be initialized properly. By default, this is all handled automatically in the included SurvivalController blueprint by the Initialize function, which is run on Event BeginPlay.
If attempting to implement the health manager in your own controller, you will be required to run the components function called Event Initialize on startup, parsing a reference to the player controller.
In order to have health get impacted on events such as players getting shot and other in-game events, you need to hook up the event TakeDamage (which is within C_Manager-Health) to the controller event Event AnyDamage. This is a standard event node included in the UE4 engine and can be used to apply any amount of damage to actors, as well as parse what type of damage was used. All that is required for this connection is to, within the controller’s event graph, connect the execution pin, damage amount and damage type from the Event AnyDamage node to the TakeDamage event node which can be accessed via the C_Manager-Health reference within your controller (see image below for reference).
Similarly, within your character event graph, it is necessary to parse information from the blueprint interface event (see Requirements above) Event Damage Event to the controller version of Event AnyDamage. This is already handled in the included SurvivalCharacter (see image below for reference).
Settings
Setting | Details | Default Value |
---|---|---|
Max Player Health | This value determines what the maximum player health value can be. In most cases, this should not need to be changed for standard survival game mechanics. May be altered to accommodate advanced/alternate feature sets such as character levelling systems and so on. | 100.0 |
Enable Falling Damage | If set to true, players will receive damage when they fall further htan the SafeFallDistance based on the FallDamageRate. If set to false, falling damage is disabled. | True |
Safe Fall Distance | This value determins what the maximum height a player can fall is before they receive falling damage. | 200.0 |
Fall Damage Rate | This value determines how much damage the player will receive based on their fall. The value is expressed as an amount of health to be deducted for every 100 units over the Safe Fall Distance the player falls. For instance, if the player falls 100 units over the Safe Fall Distance and this value is set to 25, they will lose 25 health. If they fall 200 units over, they will receive 50. | 10.0 |
Fall Height Offset | This offset is used to allow for a small offset to heigh/fall calculations to be applied. This can be useful in correcting calculations based on the update frequency. For most cases, this should be left at default values. | 20.0 |
Low Health Visual Effect | The visual effect (if any) used to indicate to the player low health values. Will come into effect when the player's health crosses the Visual Effect Threshold. | Saturation - Desaturation |
Visual Effect Threshold | Once the player's health drops below this level, the Low Health Visual Effect (if any is set) will kick in. | 15.0 |
Considerations
No special considerations required for this feature.
How do players regain their health over time??
Hey Noel. By default there is no regenerative health implemented in the template. You could easily add in a simple timer to add a small amount of health over time though. You could implement this either in your player controller, or in the health manager itself and would basically just be something along the lines of this http://prnt.sc/dz2en5
Regenerating health is a great idea and I’ll slate it in for consideration in a future update!
I was wondering if we couldn’t do a health regeneration attached to the bed, and simulate actual sleep to regain health, energy and stamina.
I will be adding the ability to pass time and recover resources from sleeping in a future update. 🙂