Help needed in figuring out how to damage enemies

Hello once more, I was wondering if anyone could help me out with a problem I’ve been having for a while now.

So I’ve trying to create a system of dealing damage to the enemy, which by itself is easy enough as setup works for that:

The problem however is that I don’t want the player to be always able to damage the enemy when they hit them. 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.

Instead I’ve been trying to create a setup that would instead allow me to determine on an enemy-by-enemy basis whether they should be able to take damage from a particular attack using Interface Blueprint and a parent class blueprint to all enemy types.

So with my revised setup for my character’s basic attack, first it communicates to the Interface Blueprint I created instead of directly applying damage.

Then the Interface Blueprint is called upon within the parent Enemy Base blueprint.
enemy_base_baseball_hit

Then if the enemy is able to be damaged, then the damage event will be called up via the Interface Blueprint again from the player character’s blueprint.

damage_interface

At least that’s how its supposed to work but for some reason I can’t actually get it to work as intended. Nothing happens when the player attacks the enemy as opposed to directly applying damage to the enemy, which as I already explained is not I want to do.

Can someone please explain to me why my setup isn’t working and how I can fix it?

Thanks in advance!

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.

I appreciate the effort but I’m not sure that your solution is the one for the situation I’m talking about.

What I meant for example, was that jumping on Enemy Type #1 would inflict damage on the enemy, while Enemy Type #2 would instead inflict damage on the player and Enemy Type #3, the player would bounce off the enemy without either the player or the enemy taking damage. Or the player wouldn’t be able to damage the enemy with a particular attack unless a specific condition is met, such as an enemy getting stunned.

And its not just damage, I’m also looking at implementing other different effects as well, such as when the player hits an enemy that can’t be damaged with a particular attack, a different sound effect will play upon the player making contact with the enemy and getting pushed backwards from the recoil.

So basically I’m looking to make a modular system for the player’s attacks that will call different events based on the situation at hand i.e. Attack: Damage for when an attack succeeds, Attack: Deflect when an attack is repelled by the enemy, or Player Damage if attacking the enemy will cause damage to the player.

I hope clarifies things a bit.

Sounds like a job for an Interface. You send a message to an enemy with the desired data and each enemy type interprets it. You could but don’t need to use the damage system for - but it does utilise Damage Type that could facilitate the behaviours you’re after.

And if you’re after ultimate modularity, then inherited actor component communicating with interfaces are the answer.

Good luck!

I’m already using an interface:

It’s just not working for some reason, like I said in my initial post, nothing happens when the player attacks the enemy. The only way I’ve been able to deal damage to the enemy is to apply damage directly instead using an interface:

The problem with though, is that I have no ability to customize the way that the player’s attack interacts with different enemy types.

I don’t know whether the problem with my setup is something to with the interface or something else entirely and that’s what I need help.

image

You forgot to specify the actor instance. should be Self. A lot of nodes default to self, one does not. Pretty annoying actually.

It still doesn’t work:

apply_damage

Do I have it set up wrong or is there something else that’s causing the problem?

  • let’s say is the interface with a bunch of interactions, one of them being BatDamage (the float Input is optional):

  • is the enemy:

  • is the player dishing it out:

You want to send a Message.

So I replaced the Baseball Bat Damage node with a message to the interface but it required a target to be connected to it. Not knowing what to do I tried promoting the target into a variable to see if that would work but it didn’t.

Okay, so after doing some testing with print string, I’ve determined that it is indeed the Baseball Bat Damage interface message that is causing the problem.

I tested every part using print string and only the Baseball Bat Damage message didn’t return a message from the print string.

Unfortunately though, I still can’t figure out how to get the interface message to properly connect to the player character’s blueprint.

Can anyone please help me out with ? I honestly have no idea on how to get the interface message to target the player character’s blueprint. I’ve tried searching with Google and I’ve tried watching various video tutorials about interface blueprints but I haven’t been able to come up with anything that would resolve problem.

So I’ve managed to further confirmed my hypothesis by applying the damage directly within the enemy blueprint and it ended up working.

But isn’t the solution to my problem because I want all the damage events to be located within the player character’s blueprint so that any modifications that I make will be applied to every enemy blueprints.

The only other alternative I can think of is casting and I’m not sure that’s a good idea.

I would much rather figure out how to get the interface message to properly communicate with the player character’s blueprint, but as I keep saying, I really someone’s help with . I just can’t seem to find the solution myself after scouring the internet again & again with no luck.

Assuming the above is the enemy attempting to message the player (or rather, what we’ve hit with the bat), what is the Target here - how is reference obtained? Is it valid?

The target is a Object variable type:

target

I know is incorrect and I just chose to promote the Target to a variable because there wasn’t any better options available in the list of Object references I could see. Just throwing crap at the wall to see what would stick as it were.

I just don’t know to how get the player character blueprint to be referenced as a target for the interface message.

Yeah, that wouldn’t work. Creating a reference var does nothing on it’s own. There’s 100k objects:

image

We need to ensure we’re sending the message to the correct one.


Is the enemy sending the message? Does print? If you print Other Actor’s display name after the hit, does it make sense?

I didn’t really think it was going to work, I was just doing something random since there wasn’t any other obvious options available.

Yes, the enemy is the one sending the message and yes the above does print.

It’s that is specifically not working. Like I said, when I cut it out of the equation and instead placed the Apply Damage in its place then the damage setup actually works.

The Baseball Bat Damage interface message doesn’t have a proper connection to the player character blueprint and that’s what is causing the problem.

Print Other Actor name after the Hit - what do you get?

Also - does the player implement the interface?


Both make no sense. In the top one the enemy damages itself, the bottom has invalid target. Also, what’s up with the parent call - probably irrelevant but there are clearly more elements at play.

Essentially, there are few elements to a working interface:

  • sending a message to the correct actor:

image

  • that class needs to implement that interface, and function / event:


However:

I do not see a point in doing . You’ve already sent a message, why bother with applying damage? Add data to the interface instead.

Not saying there is no point or that it wouldn’t work, just that I am not seeing it :wink: You may have your reasons, ofc.

I feel like it’s overcomplicated to begin with. I wouldn’t use an interface for attacks or damage.

Baseball bat: On Hit > Apply Damage
Enemy: Event AnyDamage… do your checks… for example…

  • If the enemy is wearing spikes, ApplyDamage back to the player.
  • If in front of enemy (need a function to check that), don’t do any damage.
  • If behind enemy with no spikes, kill enemy.
  • If enemy can’t be damaged, do nothing.
    You can do whatever checks you want at point.

The damage event doesn’t actually do any “damage” until you tell it to.

won’t work because DamagedActor isn’t set so you’re not applying damage to anything. But why you’re going through an interface, through a parent, through another interface??? Makes my head spin. On Hit, Apply Damage… that’s all you have to do.