#spawn entity facing the player
1 messages · Page 1 of 1 (latest)
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')```
cool! thank you very much!
oh does this only work on the beta api?
I tried and it said spawnEntity only takes 2 arguments
just take out {initialRotation:yaw}