Skip to content

Instantly share code, notes, and snippets.

@baba-s
Created March 22, 2024 08:01
Show Gist options
  • Save baba-s/0cfc8ea10256ab3e142db45ce9db1271 to your computer and use it in GitHub Desktop.
Save baba-s/0cfc8ea10256ab3e142db45ce9db1271 to your computer and use it in GitHub Desktop.
using UnityEngine;
namespace Kogane
{
public static class TransformExtensionMethods
{
public static Vector3 TransformPointUnscaled
(
this Transform self,
in Vector3 position
)
{
var localToWorldMatrix = Matrix4x4.TRS
(
pos: self.position,
q: self.rotation,
s: Vector3.one
);
return localToWorldMatrix.MultiplyPoint3x4( position );
}
public static Vector3 InverseTransformPointUnscaled
(
this Transform self,
in Vector3 position
)
{
var worldToLocalMatrix = Matrix4x4.TRS
(
pos: self.position,
q: self.rotation,
s: Vector3.one
).inverse;
return worldToLocalMatrix.MultiplyPoint3x4( position );
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment