Last active
August 29, 2015 14:23
-
-
Save smeevil/b235969299cac4d2eb56 to your computer and use it in GitHub Desktop.
Unity Get Angle of Transform to Self
This file contains hidden or 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
public static float GetAngleOfTransformToSelf(Transform other, Transform origin, bool debug) { | |
var angle = (Math.Atan2(other.position.z - origin.position.z, other.position.x - origin.position.x)*Mathf.Rad2Deg); | |
angle += origin.rotation.eulerAngles.y; | |
angle -= 90; | |
while (angle > 180) angle -= 360; | |
if (!debug) return (float) angle; | |
Debug.Log(string.Format("angle orgin {0} to {1} : {2}", origin, other, angle), origin); | |
Debug.DrawLine(origin.position, other.position, Color.white, 1.0f); | |
return (float)angle; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment