Local forward

Hi guys,

I wondered if someone could confirm something for me. According to docs, transform.forward is forward in world space; what is it’s local space equivalent?

i.e. if I want an object to move in the direction of it’s blue axis

Vector3 localForward = transform.worldToLocalMatrix.MultiplyVector( transform.forward );

Is this what you are looking for?

Just use the Vector3 constants for local space directions, i.e.:Vector3.forward, Vector3.up and Vector3.right.

You can use the TransformDirection to use it as local. (:

Vector3 forward = obj1.transform.TransformDirection(Vector3.forward);
// point
internal static void ToLocal(ref Vector3 worldPoint, ref Quaternion worldRotation, ref Vector3 worldPosition, out Vector3 localPoint)
{
    localPoint = Quaternion.Inverse(worldRotation)*(worldPoint - worldPosition);
}
internal static Vector3 ToLocal(ref Vector3 worldPoint, ref Quaternion worldRotation, ref Vector3 worldPosition)
{
    return Quaternion.Inverse(worldRotation)*(worldPoint - worldPosition);
}
internal static Vector3 ToLocal(Vector3 worldPoint, Quaternion worldRotation, Vector3 worldPosition)
{
    return Quaternion.Inverse(worldRotation)*(worldPoint - worldPosition);
}


internal static void ToWorld(ref Vector3 localPoint, ref Quaternion worldRotation, ref Vector3 worldPosition, out Vector3 worldPoint)
{
    worldPoint = worldRotation * localPoint + worldPosition;
}
internal static Vector3 ToWorld(ref Vector3 localPoint, ref Quaternion worldRotation, ref Vector3 worldPosition)
{
    return worldRotation * localPoint + worldPosition;
}
internal static Vector3 ToWorld(Vector3 localPoint, Quaternion worldRotation, Vector3 worldPosition)
{
    return worldRotation * localPoint + worldPosition;
}


// vector

internal static void ToLocal(ref Vector3 worldVector, ref Quaternion worldRotation, out Vector3 localVector)
{
    localVector = Quaternion.Inverse(worldRotation)*worldVector;
}
internal static Vector3 ToLocal(ref Vector3 worldVector, ref Quaternion worldRotation)
{
    return Quaternion.Inverse(worldRotation)*worldVector;
}
internal static Vector3 ToLocal(Vector3 worldVector, Quaternion worldRotation)
{
    return Quaternion.Inverse(worldRotation)*worldVector;
}


internal static void ToWorld(ref Vector3 localVector, ref Quaternion worldRotation, out Vector3 worldPoint)
{
    worldPoint = worldRotation * localVector;
}
internal static Vector3 ToWorld(ref Vector3 localVector, ref Quaternion worldRotation)
{
    return worldRotation * localVector;
}
internal static Vector3 ToWorld(Vector3 localVector, Quaternion worldRotation)
{
    return worldRotation * localVector;
}

I wanted to wake up this topic and I also want to wake up outsource info. :smiley:

https://www.reddit.com/r/Unity3D/comments/p8rpqk/does_vector3forward_give_the_local_direction_or/

Vector3 localForward = parentTransform.localRotation * Vector3.forward;