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

Started by BeanieBoiGaming on Tue, 09/27/2022 - 07:46

Topic category: Help with modding (Java Edition)

Last seen on 11:07, 30. Sep 2022
Joined Sep 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
How do I make a mob only move when a player is not looking at it?
Tue, 09/27/2022 - 07:46

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 19:39, 2. Dec 2022
Joined Dec 2013
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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.