Last active
March 22, 2024 20:16
-
-
Save hobione2k/b98bfb18a3855c05a903f5100026e940 to your computer and use it in GitHub Desktop.
ClusterScript 特定方向に向ける (Z軸 +z方向を前とする)
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
const rad2Deg = (r) => (r * 180) / Math.PI; | |
const aimAt = (pos, target) => { | |
const dir = target.clone().sub(pos); | |
const angleY = rad2Deg(Math.atan2(dir.x, dir.z)); // Y軸回転 | |
const d = new Vector2(dir.x, dir.z).length(); | |
const angleX = -rad2Deg(Math.atan2(dir.y, d)); // X軸回転 | |
return new Quaternion().setFromEulerAngles(new Vector3(angleX, angleY, 0)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
使い方