Tutorial

While working with UDK (Unreal 3) and Kismet, I came up with some solutions to issues I found which are simpler and neater than the “commonly offered” solutions, purely in Kismet visual scripting.

The following is a health regeneration system which is both relatively simple, works smoothly and has a delay in starting health regeneration after taking damage.

Part 1 – “Have I taken Damage”

First, we need to know when we’ve taken damage, and hence should not be regenerating health in the first place!

Create the following;

  • Player Spawned (New Event / Player / Player Spawned)
  • Take Damage (New Event/ Actor / Take Damage)
  • Attach to Event (New Action / Event / Attach to Event)

For the Take Damage’s options, now set;

  • Damage threshold to 1
  • Max trigger count to zero
  • ReTrigger delay to 0.01
  • Player only to off (yes, off)

Right click on the “Instigator” output of Player Spawned and select “Create New Object Variable”

Let’s then connect them, as follows;

hr1

We can now detect when the player has been damaged – every time he does so, “Take Damage” will now fire. With that done, we need to now set up the system will will use for delaying regeneration based on damage taken, and this will be done by declaring a boolean variable, “Taken Damage”, and set up a delay in regenerating health.

Create the following;

  • Bool (variable) (New Variable, Bool)
  • Bool (action) (New Action, Set Variable, Bool) – two of these (remember, you can copy/paste Kismet objects!)
  • Delay (New Action, Misc, Delay)

Name the Bool’s (variable) as “TakenDamage”, and leave it as false – this declares the Boolean name. We now want to add two instances of checks on this which you can do via – New Variable / Named Variables in Persistent Level / TakenDamage.

  • For each of the Bool (variable)’s, right click on “value”, then “Create New Bool Variable”. Change one of those to False.
  • Again for each of the Bool (variable)’s, right click on “Target”
  • In the option of the Delay, set it to five seconds, and turn on “Start will restart”

Now, the logic we want to set is this – when the player takes damage, it triggers a 10s period when the “Taken Damage” boolean is true. The logic for is connected as follows;

hr2

(Note the green checkmark on “TakenDamage” – if this is a red cross instead, you have not properly declared the boolean variable!)

Let’s examine this – again, when the player takes damage it triggers “take damage”. This uses the first Bool (variable) to set “TakenDamage” to “True”. It also stops the timer delay. 0.1s later, the timer is now restarted (To create the delay, right click on the “out” node and select “Set Activation Delay”). If the Delay is allowed to finish – by not taking damage for those five seconds – the second bool is now triggered, and “TakenDamage” is now set as “False”.

Part 2 – “Regenerate Health”

Now we have set up a system to tell us when we should be regenerating health, let’s make that happen.

Create the following;

  • Player Spawned (New Event / Player / Player Spawned)
  • Delay (New Action, Misc, Delay)
  • Modify Health (New Action / Actor / Modify Health)
  • Compare Bool (New Condition / Comparison / Compare Bool)
  • TakenDamage Bool (New Variable / Named Variables in Persistent Level / TakenDamage)
  • Player Variable (New Variable / Player / Player)

Now;

  • In the Delay, set it to 1 second
  • The Modify Health needs to have it’s Amount set to 5 and “Heal” checked.
  • For the Player Variable, uncheck “All Players”

And we can then connect them as follows;

hr3

We begin the logic looping when the player is spawned. We check with the Compare Bool to see if “TakenDamage”  is false, if it is then we add 1 to the Player’s health with the Modify Health. Regardless if it is true or false, we trigger a delay of 1 second after which the Compare Bool is checked again, etc.

This now works! You can use other values – a shorter delay and a smaller heal amount, for instance, to create a smoother regeneration, if you wish.

(If it is not working, set your World Properties to “utgame”)

Part 3 – Test trigger

Let’s set up a simple trigger to test this with;

Make a Trigger in the main UDK window (Add Actor / Add Trigger), and edit it’s properties (F4), unchecking “Hidden”. Now place it near to the player spawn. With it selected, in Kismet right click and select New Event using Trigger_(x) / Used. Then create;

  • Modify Health (New Action / Actor / Modify Health)
  • Player Variable (New Variable / Player / Player)

Now set the Modify Health to, say, 10 damage per press, and set the Max Trigger Count of the Trigger to zero! If we then connect these up;

hr4

…We then have a trigger which damages the player when we trigger it, and which we can use to test the health regeneration!

I hope this was helpful!

//AndrewC