Damaging a Custom Character Controller
Last updated
Was this helpful?
Last updated
Was this helpful?
Important: If you haven't already done so, it is recommended that you set up your player with a EmeraldGeneralTargetBridge first to ensure everything works correctly. If you haven't already done this see the section.
Important: It is expected that you have C# coding knowledge before proceeding.
All damage is handled through an interface script called IDamageable. This script acts like a bridge that allows damage calls to be received by any script that uses the IDamageable interface. This is important for custom character controllers as users can then receive the damage call to then damage their character controller's health.
To start off, create a copy of the included EmeraldPlayerBridge and rename it to the desired name. This will be used to damage your custom character controller. There are notes where you should add your custom code within the EmeraldPlayerBridge script.
When a player is damaged, it will call the Damage function within this script as shown below. This will call an additional function called DamageCharacterController.
The DamageCharacterController is where you should put all your character controller's damage code and what happens when your player dies. Because this varies based on character controller, an example can't be provided.
All relevant functions within the EmeraldPlayerBridge script are virtual and allow you to override them to add your own code.
Below is an example of a script derived from the EmeraldPlayerBridge. At the top are the two most relevant functions; the Start (which should be used for initializing your health values) and the DamageCharacterController (which should be used for damaging your character controller and handling what happens when its health reaches 0).
The other functions can be used to set your character controller's actions such as dodging, blocking, Triggering, given they are supported. By default, these are all set to false.