using UnityEngine; /// /// A Transform Extension that ignores scale for TransformPoint operations. /// public static class TransformExtensions { /// /// Transform position from world space to local space unscaled. /// public static Vector3 TransformPointUnscaled(this Transform transform, Vector3 position) { var localToWorldMatrix = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one); return localToWorldMatrix.MultiplyPoint3x4(position); } /// /// Transform position from local space to world space unscaled. /// public static Vector3 InverseTransformPointUnscaled(this Transform transform, Vector3 position) { var worldToLocalMatrix = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one).inverse; return worldToLocalMatrix.MultiplyPoint3x4(position); } }