Object atack facing another

How can i do to know if the character is attacking another from behind or in front of?

  • I want to make a fighting game with swords, and i want that if my main character is on def, and is atacked from behind, get damaged, but if the other character attacks him being in front, dont receive damage, can someone help me with this? Thank u so much!!!

There are many possibilities, depending on what you’ve already done.

I suppose to be on defense, your character need a pushed key ? So basically you could have conditions like
The defense key is pressed
character2.X() < character1.X() => damage
the sprite orientation of character1 is “right” => damage
character2.X() > character1.X() => damage
the sprite orientation of character1 is “right” => NO damage

idk if you see the point, and this is not perfect, because idk what you have already in your game. But this is an idea, compare sprite orientation, X() coordinates of both character, and “defense” condition.

Yeah i see what u did there, mmm i think it can work, if enemy.X > character.X and ( the enemy is always facing the character), character is not facing the enemy, then it damages, but if is facing and defending dont receive damage… umm lets see i will prove it soon and i will say what happens thanks!

Why bother?

if enemy in collision with player
— If enemy.orientation = player.orientation then -enemy.variable(damage) to player.hp