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.
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.
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.
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.
you have a image?
https://imgur.com/gallery/mcreatorlook-vMs6T8Q here is my proposition i dont know works
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.
How can i change height eye ? PLEASE
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.
Thank you so much for helping me