Ok thanks but my player will always have his shield on so when I'll press the shield button, I will play a little animation in guard position. But yeah your are right I have to stay realistic.
Thanks a lot if you have other advices to give please do I want to learn ^^
Just try to break the problem down into smaller steps, like:
1. what do you need? -- a directional shield.
2. how does a directional shield behave? -- it intercepts the process of damaging.
3. Under what conditions?
--Only when the shield is pointed toward source of damage. (A shield does not protect the back, as we know.)
So far, this had nothing to do with programming, it was just about general shield mechanics. However, if you had kept this in mind beforehand, you would have known that the first reply to your post couldnt possibly provide such shield, as direction was not taken into account at all (not to discredit help in any way, this is just for the sake of feedback on your own thought process). Instead, you were surprised that is was so easy.
Now to continue, geometry is added:
4. Now, point 2 is straightforward to implement, but how do we know when shield points toward the source of damage (3)?
-- pointing towards something implies a
pointer, its
angle and a
something to point to.
And game maker:
5. How does this information translate to game maker?
-- pointer = player and his facing. (Object)
Something = attack (hitbox?)
Angle = angle between those two
6. What are the concrete gml parameters i need, to extract that information?
-- player and facing = player.x, player.y and player.facing (you define facing).
Attack = hitbox' x and y.
Angle = point_direction() with player x and y, and attack x and y.
From there it becomes purely mathematical, as you only work with the player.facing and point_direction, which are 2 angles. The exact code/math is already given by Yal, which you can look up and is not my point here.
Edit: as you might have noticed, another snaller problem is introduced in the process: when is the shield "facing toward attack"? It is a sensitivity (angle range) you need to determine for yourself. This is because you dont want the shield to be autistic and block only at the exact angle toward the enemy (which would be a miracle), rather a range.
Hope this helps you out in the root of your problem. Good luck