How I can make a entity despawn if player looks

Started by Igor_santuchi on

Topic category: Help with Minecraft modding (Java Edition)

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How I can make a entity despawn if player looks
I'm trying to make an entity that disappears when the player looks at it
Pls Help
Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
In one of my mods, I execute…
Wed, 07/10/2024 - 21:53

In one of my mods, I execute a command that gives a status effect to certain kinds of entities the player looks at.

Such as: /execute as @e[type=minecraft:villager] at @a[distance=..12] facing entity @s feet positioned ^ ^ ^1 rotated as @a[limit=1] positioned ^ ^ ^-1 if entity @a[distance=..0.1] run effect give @s minecraft:slowness 1 255 true

"[distance=..12]" controls how far away the command works from. The way it's written here allows it to work within 12 blocks. If you look at the entity from further than 12 blocks away, nothing will happen.

"[distance=..0.1]" controls how directly you have to be looking at the entity. If you imagine a bubble around the entity's eyes, and say the game thinks you're looking at the entity if you're looking at that bubble, this number controls the size of that bubble.

You could either give them a specific effect like unluck 255 and then constantly check to see if your entity has unluck 255 or not and despawn them if they do. Or, instead of giving them a status effect, you can try teleporting them into the void.

Joined Nov 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
you have a image?
Thu, 07/11/2024 - 16:45

you have a image?

Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I suggested executing a…
Thu, 07/11/2024 - 18:31

I suggested executing a command- which should be done every tick.
You can have an on tick procedure on the entity itself that executes a command at the location of the entity.

Then you can check for the status effect using the same procedure in an if statement and then despawn the mob if it detects that it has the effect with the correct amplifier.


As for Ousieks' suggestion, I haven't tested it, but that looks to me like it would despawn the entity as long as you were both facing the same direction. It isn't able to check if you were looking at the entity specifically.

Joined May 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How can i change height eye …
Sun, 11/03/2024 - 11:20

How can i change height eye ? PLEASE

Joined Jan 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Apologies. Note that I'm not…
Sun, 11/03/2024 - 23:35

Apologies. Note that I'm not an expert at these types of commands... I tried playing around with it for a good while and searched for solutions online, but I haven't been able to figure out how specify the height of eye level- or how to guarantee the command executes when you look at the entity's eyes regardless of their height.

Even when you use the command I posted, it only seems to work fine for two block tall mobs. When using it on something smaller, you have to look above the entity's head- whereas with taller entities you look at their body. It seems to be using the player's eye level for this.

I haven't been able to watch the entire thing yet, but this video is the more useful/relevant information I've found on the matter:
https://www.youtube.com/watch?v=fGlJpli5cYc "How to Detect Where the Player is Looking in Minecraft" by Cloud Wolf. It seems particularly well-made, from what I could tell skimming through the video.

Joined May 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thank you so much for…
Mon, 11/04/2024 - 16:45

Thank you so much for helping me