Skip to content

Instantly share code, notes, and snippets.

@eioo
Created January 22, 2018 17:01
Show Gist options
  • Save eioo/46620d678e13410bc6e127a3cd7ffa8c to your computer and use it in GitHub Desktop.
Save eioo/46620d678e13410bc6e127a3cd7ffa8c to your computer and use it in GitHub Desktop.
function angleCalculator(enemyPos : IPos, myPos : IPos) : IAngle {
const deltaX = myPos.x - enemyPos.x;
const deltaY = myPos.y - enemyPos.y;
const deltaZ = myPos.z - enemyPos.z;
const pitch = Math.atan2( deltaY, deltaZ );
let yaw;
if (deltaZ >= 0) {
yaw = -Math.atan2(deltaX * Math.cos(pitch), deltaZ);
} else {
yaw = Math.atan2(deltaX * Math.cos(pitch), -deltaZ);
}
return {
pitch,
yaw,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment