Created
May 19, 2020 03:52
-
-
Save the6th/d25d5ba8527e57814b6e6a6a96228a15 to your computer and use it in GitHub Desktop.
World space rotation を local spaceに変換するHelper関数
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
using UnityEngine; | |
public static class TransformHelper | |
{ | |
/// <summary> | |
/// World座標系のQuaternionを対象のTransformのlocalRotationに変換する | |
/// </summary> | |
/// <param name="target">対象のTransform</param> | |
/// <param name="worldRotation">World座標系のQuaternion</param> | |
/// <returns>localRotation</returns> | |
public static Quaternion InverseTransformRotation(this Transform target, Quaternion worldRotation) | |
{ | |
return Quaternion.Inverse(target.transform.rotation) * worldRotation; | |
} | |
/// <summary> | |
/// World座標系のEulerAnglesを対象のTransformのlocalEulerAnglesに変換する | |
/// </summary> | |
/// <param name="target">対象のTransform</param> | |
/// <param name="worldEuler">World座標系のEulerAngles<</param> | |
/// <returns>localEulerAngles</returns> | |
public static Vector3 InverseTransformEulerAngles(this Transform target, Vector3 worldEuler) | |
{ | |
return target.InverseTransformRotation(Quaternion.Euler(worldEuler)).eulerAngles; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
usage