Created
January 22, 2018 17:01
-
-
Save eioo/46620d678e13410bc6e127a3cd7ffa8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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