Local Multiplayer Self Damage Problem

When either player is behind another they can deal damage I do this by getting input key down time while a bool is set from the collision behind the player and when the key down is greater than 0 it will subtract health from the player.

My problem is that when I am behind the player I can damage them fine and only their health goes down but when I go infront of the player and then press the same action it will take away my health even though I’m attacking and not the other player.

Both actors are spawned from the same character bp and I assume the problem derives from it using the player controller since its index is 0 and doesnt account for the other players.

How would I go about fixing this? How do I only subtract health from the player that Im behind and prevent myself from damage when they are behind me?

Every other variable is set in the widget so it uses get owning player pawn so each character has their own individual variables its only the damage that is being set from inside the player bp itself so yeah Im not sure to how to go about this.

Thanks!

you basically just need to have a way to reference the actor your overlapping so that you can damage them. below is a little example i threw together that should work in your situation, though im sure theres a better way to go about it. what i did is when the input is pressed i got all actors of the class that can be damaged then for each one i checked to see if i was overlapping their damage box. if true then i apply damage. the cast should be superfluous but my editor was being weird about it so i added it in.

I tried implementing this but It only damages the player I’m controlling, also the way I have the health set up is by dividing a “current hp” float by a set “hp” float so I just subtract from the current hp to get the value and plug that into the hud when I want to damage the player.

Im doing this from inside the character bp itself and I’m assuming thats why its damaging the character I’m controlling only?

EDIT

I just got the same variables from the cast and that worked on damaging the other character, but would that mean I would have to cast to all of my characters each time this is pressed since I have multiple characters rather than only this one?