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.
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.
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?
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.
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):
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.
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.
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.
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.
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.
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?
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.
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.
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.
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.