Can I check whether a player is behind a mob?

Can I check whether a player is behind a mob? - Smiling woman with chess looking at camera

I am building a Adventure map and I want to include a Backstab-like feature, where when player is behind "Mob" he is given a diamond sword with sharpness 99999. If he is not, the sword is removed. (Sword will have a durability of 1 so it breaks when you use it)

Is that possible in any way?



Best Answer

Yes, but you need a lot of command blocks. The more you'll have, the more accurate this will be. Basically you need to have a command block for every mob rotation or so.

For example:

The first command block checks if the player is meeting the requirements while the mob is facing the 0 to 5 degree y rotation.

The second command block checks if the player is meeting the requirements while the mob is facing the 5 to 10 degree y rotation.

The third command block...

...

...

...The < insert big number here > command block checks if the player is meeting the requirements while the mob is facing the 355 to 360 (=0) y rotation.




Pictures about "Can I check whether a player is behind a mob?"

Can I check whether a player is behind a mob? - From above dreamy young female in casual wear lying on floor with eyes closed and hand behind head while listening to vinyl record player
Can I check whether a player is behind a mob? - Dreamy woman lying on floor near vinyl record player
Can I check whether a player is behind a mob? - Top view dreamy young female with red lips wearing casual wear lying on floor with eyes closed and hand behind head and listening to vinyl record player





The White Stripes - Seven Nation Army (Official Music Video)




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Victoria Borodinova, Victoria Borodinova, Victoria Borodinova, Victoria Borodinova