Hi! I’m pretty new to ue4 and can’t find a really suiting tutorial for this… I’ve a working AI that spawns on a location, walks to random spots on her nav mesh and as fast as I enter the nav mash she runs towards me…
Now to my problem… When I wanna shoot her I need some sort of health system on her… Now when my projectile hits I only get my print string… What have I done wrong or have I missed something important out? I’ll add some screens to my two blueprints
Oh and ye, I’m using the FPS-bluprint project
Cheers
Within your actor you need to grab that input and handle it somehow. There should be a node called “took damage” or very similar which receives all kinds of “apply damage” events and allows you to calculate shields and all that stuff.
TLDR: You already deal the damage. Now you need to put a HP system behind it.
HP should not be more than a variable within your AI character (so not the AI blueprint or the behavior tree but the character which the AI possesses).
You receive the applied damage, subtract it from your current HP and set this as new HP value.
If you go below 0 you destroy the actor or do whatever your actor should do when he died.
That’s all logic you will have to implement yourself. There is honestly not much too it…
Ye. check this http://i.imgur.com/T6taNeV.png On the bottom of this picture I’ve tried to make some sort of health system inside my AI’s blueprint, maybe it’s completely wrong?
In your Projectile class when you apply damage you apply it to your player character and not to whatever got hit and you also only apply damage when the hit actor is the player character.
Just pull out the “Other Actor” line and directly put it into “Damaged Actor”. You can do the checks later on at the actually hit actor… or just ignore it all together. Nothing is happening if you don’t have a “took damage” node.
Currently you have the damage set up to hit player 0 only. You should set damaged actor to “other actor”. You can also do a cast to from your actor to your ai class, then run the damage from that. This makes it check to see if what you hit was an AI, and if so, deal X damage.
You need the HP system pretty much like you had it in the character with the “AnyDamage” node and for the “ApplyDamage” node just pull the “Other Actor” to the “Damaged Actor”. Remember to always check where something doesn’t work.
Always check if anything at all comes out of the “Any Damage” node and if you have a signal right before you use the “Apply Damage” node.
Oh and get rid of that branch. You probably don’t even need the ComponentHit but can use straight up “Event Hit” and pull that straight to apply damage.
I managed to make a much simpler version of what you’d put into the second screen shot and got a health system for enemy AI which can easily be implemented to any character.
Sly edit here: Realised a better way of handing the health check, which was to deal the damage first and then have the set command execute the check after it completed. the below can now be ignored unless you wish to circumnavigate my horrible drawings and replicate the original version.
Note: For some reason, even though the value function on that blueprint is less than or equal to, it seems to only respond to less than for destroying the actor, as I had the health default set to 10 and it died after 11 bullets. That or it destroys on additional damage after it hits zero because the function to check health isn’t being called until it receives damage once again after it goes below the value…
Either way, it seems to be that the best way to avoid having to do a constant health check for all actors on every tick is to just set that value to 1 so it can die on 0.
Sorry if my explanation isn’t all too great, but the blueprint should have all the info you need either way.