#spawn entity facing the player

1 messages · Page 1 of 1 (latest)

lost gate
#

Hi! I was wondering if there's any way I could summon an entity facing the player. I need this for a block I'm making that also has an entity and I wanted the entity to spawn looking at the player but I'm not sure how to do this, could anyone help me, please?

#

spawn entity facing the player

heady vale
# lost gate Hi! I was wondering if there's any way I could summon an entity facing the playe...
const player = world.getPlayers()[0];
const entityLocation = {
  y: player.location.y,
  x: player.location.x + -2.5, 
  z: player.location.z + 2.5
};

let dx = player.location.x - entityLocation.x;
let dy = player.location.y - entityLocation.y;
let dz = player.location.z - entityLocation.z;

let yaw = Math.atan2(dz, dx) * (180 / Math.PI)-90;
let distanceXZ = Math.sqrt(dx * dx + dz * dz);
let pitch = -Math.atan2(dy, distanceXZ) * (180 / Math.PI);

player.dimension.spawnEntity('minecraft:witch', entityLocation, {initialRotation:yaw}).setRotation({x:pitch, y:yaw})```
or just use a runcommand like
```js
player.runCommand('summon witch ~~~2 facing @p')```
lost gate
#

I tried and it said spawnEntity only takes 2 arguments

heady vale