#Despawn mob when you look at him

1 messages · Page 1 of 1 (latest)

short night
#

Im doing a small horror addon and I'm wondering how can I make the mob disappear when the player look at him, its using commands? Behiavor? How can I do something like that?

severe sluice
#

easiest way is to use scripts

#

use the getEntitiesFromViewDirection() method on the player

#

do you have any experience with scripting?

pastel venture
pastel venture
short night
pastel venture
#

its kinda easier since its just 1 command lol, no need scripts for that

#

but if you want i can use scripts

short night
# pastel venture ye

I was looking into some addons and saw that some of the use functions and dummy to call the despawn event to the mob

pastel venture
#

just add type= in the event so itll affect just your entity

short night
pastel venture
short night
#

Still no

pastel venture
#

well, its better

#

cuz using /kill makes it red and drop xp and items yk

short night
#

Yes

#

So I may add the despawn component and force it to trigger

#

When i look at the entity

pastel venture
short night
#

Oh alright ty, I'm pretty sure I need put it in the tick.json to keep working

#

Thanks I'll try it later I'm a bit busy rn but I can ping you if an error occurs if you don't mind being pinged

pastel venture
#

SCRIPT VERSION

-# if you wanna use it

import { world, system } from "@minecraft/server";

system.runInterval(() => {
 world.getPlayers().forEach((player) => {

player.getEntitiesFromViewDirection({
   type: "prefix:yourentity"
}).forEach((e) => {

 const entity = e.entity;

 // this is the event to despawn the entity
entity.triggerEvent("your:event_to_despawn");

     });
  });
});
pastel venture
short night
urban sage
#

just use the lookat component to call an event that adds the despawn component in a component group

#

You guys are wild haha

severe sluice
#

lookat is definitely a good option, but it only works when you look at the entity's head

severe sluice
short night
pastel venture
#

That's why I also gave the script option

short night
#

Lookat looks very fine since the entity it's humanoid

pastel venture
short night
pastel venture
#

nice

pastel venture
short night
#

Just need to manage to learn how to make a entity spawn near to the player and disappear with a timer(it's no hard I mean but I'm a long time without make any addons)

short night
pastel venture
short night
#

OH

pastel venture
#

of @minecraft/server

short night
#

So this is why

#

Thanks again I'll try it too

pastel venture
short night
#

I think call a function can make it

pastel venture
smoky oracle
pastel venture
#

cool

buoyant field
#

how can I do this

buoyant field
#

im trying to do the same thing without scripts

#

can you explain to me

pastel venture