How do I make a mob only move when a player is not looking at it?

Started by BeanieBoiGaming on

Topic category: Help with modding (Java Edition)

Last seen on 06:59, 6. Mar 2024
Joined Sep 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do I make a mob only move when a player is not looking at it?

I'm trying to make a mob that only moves when you are not looking directly at it and teleports away when you look away completely. I'm not very experienced with coding.

Any solutions?

Last seen on 01:57, 19. Mar 2024
Joined Dec 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You can't to get one target…
Wed, 09/28/2022 - 13:19

You can't to get one target for checking the visibility of the mob, and you can't check all the players, so, there is no solution for this problem. I tried to create reputation system and get the same problem, tring to make the mob attack player if it's reputation is lower then 0. 
But you can try get all players in some radius and then check visibility:

get reletive vector (mob position - player position) and if the angle between this vector and player look vector is higher then 70 degrees (normal field of view), allow mob to move. But there is no procedure block for angles between two vectors so you need some maths.