Detect if i can SEE an entity?

Started by MamaLuigi on

Topic category: Help with modding (Java Edition)

Last seen on 16:52, 17. Jul 2024
Joined Sep 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Detect if i can SEE an entity?
Wed, 11/08/2023 - 12:04 (edited)

I have seen plenty of ways to detect if you are looking at an entity, but I want to be able to detect if and when you can SEE them, as in they are on the screen, or within in your FOV.

 

I would prefer if the solution just required some procedure.

 

Any help would be greatly appreciated!

Edited by MamaLuigi on Wed, 11/08/2023 - 12:04
Last seen on 18:36, 16. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I am not totally sure how…
Wed, 11/08/2023 - 16:49

I am not totally sure how you would do this, especially since FOV is a variable. (You can change it in settings, and potions, flying, sneaking, etc; can increase or decrease it.) 

In theory, you could probably approximate whether or not an entity is within the player's field of view by getting the player's look angle vectors and then the vector of the distance between the player and that entity, and seeing if the components of the vectors are within a certain radius... but I'm still not totally sure how this would work. 

It might be a little easier to check if there's a line of sight to the player, (you'd just need the line from the player to the entity, and then need to somehow check if there are solid blocks along that line), but actually checking if an entity is on screen seems very difficult. Sorry I couldn't be of more help!

Last seen on 16:52, 17. Jul 2024
Joined Sep 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
it is fine if you can only…
Thu, 11/09/2023 - 01:13

it is fine if you can only detect the player not looking at the entity, but how would i achive that?

Last seen on 18:36, 16. Jul 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
That's the problem, there…
Thu, 11/09/2023 - 02:06

That's the problem, there isn't an easy way to detect if an entity is on screen. What I meant is that it might be easier to detect if there was a line of sight, but this would be true as long as the entity has a line of sight to the player, even if the player isn't facing that direction. 

You might need to both determine line-of-sight, but then also check if the entity is more or less in the direction the player is looking. (X is greater than the player's if the player is looking east, etc.) Not a perfect solution, especially given the player can also look up and down as well as horizontally, but you might be able to get it sort-of working?