I'm making a game where the enemy can turn on its own axis in 360 degrees (top view game).
The player-controlled character has a bow. With this bow he shoots and deals damage when he hits the enemy.
I would like that when the arrow shot from the bow hits the enemy's back he would take double the damage.
I tried to make a system using arrow and enemy angles, but that system doesn't cover all cases.
Code:
if((image_angle-other.image_angle>280 && image_angle-other.image_angle<360) || (image_angle-other.image_angle<80 && image_angle-other.image_angle>0)){
other.life-=damage*2;
}else{
other.life-=damage;
}
Image of one of the inconsistencies that happen:
If the game's view was from the side, you could even use something using the angle the way I did, but as it's from above and the shot can come out at any angle and the enemy can be at any angle I couldn't think of anything.
In fact I even thought. Create an object that sticks to the enemy's back and is not visible to the player. Each detector object would have an enemy as its owner. If the arrow collides with that object, it would make the owning enemy suffer double damage.
However in the game there are arrows that go through enemies, so the arrows would end up hitting the detector object as well. I would have to make a way for the arrow to leave a mark on the enemy so that it doesn't take normal damage and then double damage (by colliding with the enemy and then with the detector object respectively).
Not to mention that from my knowledge I already knew that this alternative by itself is no longer ideal because it is not optimized, even if there was no double collision problem.