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:
- the enemies process the data (the red arrows indicate directions enemies are looking in):
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):
For something more nuanced, consider looking into how Damage Type Class works. You can see a dropdown on the Apply Damage
node.
Edit: wanted to find a similar thread I had at the back of my mind.