# Help needed in figuring out how to damage enemies

**URL:** <https://forums.unrealengine.com/t/help-needed-in-figuring-out-how-to-damage-enemies/659454>\
**Category:** Programming & Scripting\
**Tags:** unreal-engine\
**Created:** [September 30, 2022, 4:31am UTC](https://forums.unrealengine.com/t/help-needed-in-figuring-out-how-to-damage-enemies/659454 "2022-09-30T04:31:02Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Everynone](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/everynone/32/1135017_2.png) [@Everynone](https://forums.unrealengine.com/u/Everynone)\
**Post date:** [September 30, 2022, 6:17am UTC](https://forums.unrealengine.com/t/help-needed-in-figuring-out-how-to-damage-enemies/659454/2 "2022-09-30T06:17:55Z")

</div>

> [@HungryMoogle](#):
>
> There are circumstances that I want the enemy to be immune to damage such as an enemy that can’t be damaged from frontal attacks and can only be damaged from above or behind.

The initial setup is the way to go (but the other idea you propose could also work!).

When you damage an enemy, you do not really _damage_ it, you send them a bunch of data. When the enemy receives said data, it’s their job to process it and decide what happens next. way each enemy class can treat the incoming data differently.

- the player hits the enemy:

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/a/2/8/a28434b8c135fcb4c3f5242c731526803de0b89b.png)

- the enemies process the data (the red arrows indicate directions enemies are looking in):

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/9/8/29809e1a3a135bb9b1aeff0b2702ff4472779cc3.jpeg)

Using `Dot Product` is a typical method of figuring how closely directions are matching. You can even convert it to angle if needed. Here I am comparing the direction the attack came from to the facing direction of the enemy.

Dot product goes from -1 to 1.

* * *

In addition to the above, you can set up flags in the enemy (the red arrow indicates the direction the enemy is looking in):

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/b/d/6bdec2b43bb2ac885576ad7377839c6209e82e13.png)

* * *

For something more nuanced, consider looking into how [Damage Type Class](https://www.youtube.com/watch?v=MLtDgukVG94) works. You can see a dropdown on the `Apply Damage` node.

* * *

Edit: wanted to find [a similar thread](https://forums.unrealengine.com/t/limiting-a-traces-direction/235169/18) I had at the back of my mind.

---

_[View the full topic](https://forums.unrealengine.com/t/help-needed-in-figuring-out-how-to-damage-enemies/659454)._
