This site uses strictly necessary cookies. More Information

X# TransformPoint/Direction/Vector Equation?

Actually I'm working on my expansion script, however I lack of math knowledge, cannot do it myself even google I didn't know the real keyword for the answer.. I did try it before. so I put it here, hope someone can guide me.

What I need is the equation in code : - TransformPoint - TransformDirection - TransformVector - InverseTransformPoint - InverseTransformDirection - InverseTransformVector

I wish to calculate the above result without using any GameObject, which mean no transform at all. not good at math, so I only able to find out the "TransformPoint", and I put it here,

```
public static Vector3 TransformPoint(this Vector3 position, Quaternion rotate, Vector3 offset)
{
return position +
((rotate * Vector3.right).normalized * offset.x) +
((rotate * Vector3.up).normalized * offset.y) +
((rotate * Vector3.forward).normalized * offset.z);
}
```

sorry for my bad English. hope you guys understand :)

just find out I can do it like that for TransformPoint & InverseTransformPoint

```
public static Vector3 TransformPoint(this Vector3 position, Quaternion rotate, Vector3 offset)
{
return position + rotate * offset;
}
public static Vector3 InverseTransformPoint(this Vector3 position, Quaternion rotate, Vector3 targetPosition)
{
return rotate.Inverse() * (targetPosition - position);
}
```

Now need to do the direction. hope I can solve it right.

I just realize I didn't do it right, forgot to calculate the scale here is the upgrade version.

```
public static Vector3 TransformPoint(this Vector3 position, Quaternion localRotate, Vector3 localScale, Vector3 offset)
{
return position + localRotate * Vector3.Scale(offset, localScale); // ok
}
public static Vector3 TransformPoint(this $$anonymous$$atrix4x4 matrix, Vector3 offset)
{
return TransformPoint(matrix.GetPosition(), matrix.GetRotation(), matrix.GetScale(), offset);
}
```

### Your answer

### Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.