When I swing the weapon, the AI instead death not when health low then dead

  • The AI has a health bar

  • I set 10 damage every swing

  • But when I swing it instead destroy

  • I put ‘destroy actor’ so when AI hp is low, the AI destroy

below is notify trace


npc widget and damage

player damage to npc

Hey @anonymous_user_3315e26f! So there’s a couple of odd things with this script, but for the sake of time I’ll just point out why they are dying regardless of damage, and how to fix that.

image

The Taking Damage From Player node has no conditional, so whenever they take damage they are destroyed. Instead you want to place a branch no in between your Taking Damage From Player node and your DestroyActor node, and in your Taking Damage from Player Node, you should have a boolean return, and then connect that to the newly formed branch node.

Would look a bit like this (I added a delay so you can see your ragdoll)

Let me know if you have any questions!

1 Like

Hello,
I follow your steps and it works!
Thank you for your help!

I have a problem, so when the AI is 0 hp the AI does not destroy.
I set 0.2 in delay but still not destroy.

No worries, I’m back in and we’ll go over the script in a more broad sense and pick out issues and fix them one by one.

So my first thing to address is probably more of a “best practices” thing, where it’s always better to just use the raw numbers for health instead of as a percentage for calculation terms, and only change it into a percent when you send it to your UI.

image

So I’d simplify the take damage, and also take the Set Simulate Physics and move it out of the function. In case you wanna use this damage function later, some things you won’t want to simulate physics on, some might wanna do a special animation or cutscene, etc.

Minor changes back in the character BP to show when they get hit so you can debug exactly how much HP they have after they get hit.

Try that out, and watch how the health for the enemy changes each attack, then how they react when the death is to be called.


it appears the hp bar is function but the destroy actor is not
I almost forgot in the widget I bind in ‘reference character to total health’
Untitled

Ahhh something must have been hooked up wrong, I’d probably take the health bar UI out of the equation to make the logic work first then tie the health bar UI back in. Did you take out the percentage change from the main logic and change it over to the simplified version? Because I think you might be still referencing the percentage system as before. The system I had set up seems to be working, but the value it’s getting isn’t reflecting, and the enemy should be disappearing after the listed delay.

Could I see your changes to the damage system? Might be able to point it out there.

it does work but the widget is not function


So I believe this must be widget the problem?

Ahh I see, so the UI would have been broken when we changed the values, now you’re going to want to convert the health into a percent like you did before again (in a separate function) and rebind the widget.

somehow I put in widget function, the hp bar does not show the fill

Hey there @anonymous_user_3315e26f! So your Get Percent function seems to be trying to cast to the NPC character BP but your object you’re looking in is the player character. You’ll have to get a reference to the NPC and pass it in where you have the Get Player Character linked in at here.