#Entity Walk to player

1 messages · Page 1 of 1 (latest)

deep verge
#

How can I make the entity walk to the player and not be teleported directly?

if (response.selection === 0) {
  if (entity.hasTag("trader:Ui")) {
    entity.removeTag("trader:Ui");
    entity.addTag("trader:walk");
    entity.playAnimation("animation.trader.happy");
    entity.runCommandAsync("event entity @s jm:test");

    const playerPosition = player.location;

    
    const playerDirection = player.getViewDirection();


    const horizontalDirection = {
      x: playerDirection.x,
      z: playerDirection.z
    };


    const length = Math.sqrt(horizontalDirection.x * horizontalDirection.x + horizontalDirection.z * horizontalDirection.z);
    horizontalDirection.x /= length;
    horizontalDirection.z /= length;

    const scale = 1; 
    const newX = playerPosition.x + horizontalDirection.x * scale;
    const newY = playerPosition.y; 
    const newZ = playerPosition.z + horizontalDirection.z * scale;

    entity.teleport({ x: newX, y: newY, z: newZ }, entity.dimension);
  }
}
dim fog
#

Using entity.triggerEvent() you can trigger an event on your entity and that event can add the behaviour needed, can’t recall which one, investigate target I think?

deep verge
#

But i want to do it without Events if that is posible

quasi heron
deep verge
#

Why

#

Ok and how can i do it with events

quasi heron
#

we used to be able to set the entity's target in the api but it was removed due to it being buggy

#

I think

deep verge
#

And how to do it with events

deep verge
#

Hello?

deep verge
#

Pls??

deep verge
#

Hello please somebody help me with this, i want to finisch my addon🫠

reef pasture
#

Set it to attack a player

#

If you don't want it to attack the player, put also the reach_multiplier to 0.0 in the minecraft:melee_attack component

deep verge
#

Is it also possible to make that the entity walks in front of the player

reef pasture
#

I'm not sure

deep verge
#

It must be that the entity walks in front of the player because if it is teleported directly then it looks stupid

reef pasture
#

This method will make it walk where the player is because its trying to attack you

deep verge
#

yeah but it doesn't walk in front of the player

reef pasture
#

Idk

#

Maybe there is a pathfinding script somewhere that can help you

deep verge
#

If anyone knows a way to do it this way, just write it. I just do it now without, but so that the entity teleports

dim fog
#

The only existing behaviour that matches your requirements is the tempt behaviour but of course that has the challenge of requiring an item in your hand to tempt them. The wardens investigate suspicious location will kind of work but I don’t think they’ll come in front of the player like mobs do when tempted