(click image for full blueprint.)
In this example we’re learning a few new concepts.
- New Variables. We are using a float to keep track of player health. A float is a number with a decimal point (1.4, 4393.394, 2.39282, etc). Here the player starts with a health of 1 and it decreases by .2 with each hit. Floats are green.
- We are also using vectors to store locations. A vector is just three floats together that tells the game where something is located on the x, y and z axis. Vectors are yellow.
(Default variable values are: vectors are 0,0,0 and the boolean is set to true. Health is set to 1.0)
We also are using a “simple move to actor” to make a bad guy run toward the player. The bad guy must have a “Nav Mesh Bounds Volume” around him and it must be built by pressing the letter ‘p’ on the keyboard.
Then when the vectors of the bad guy and the player are close enough to being equal (by 80 units here) the player loses .2 in his health float variable.
Then we do some basic logic things with branches. Since all of this is on an event tick, it is happening very quickly. We want the player to only lose .2 in health when he is hit and not .2 every tick. So we need to stop counting for a bit and give him time to get away.
Also we want the level to start over if he loses all his health. So when his health is <= 0 movement is stopped and the level is restarted with a console command “restartLevel.”
