docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Method TransformDirection

    TransformDirection(float3)

    Transforms a direction by this transform.

    Declaration
    public float3 TransformDirection(float3 direction)
    Parameters
    Type Name Description
    float3 direction

    The direction vector to be transformed. This vector does not need to be unit-length.

    Returns
    Type Description
    float3

    The direction after transformation.

    Remarks

    To transform a directional vector, use TransformDirection(float3). To apply the inverse transform instead, use InverseTransformDirection(float3).

    Examples
    float3 dir = new float3(2, 1, 0);
    LocalTransform translationTransform = LocalTransform.FromPosition(new float3(1, 2, 3));
    // dir2 will be identical to dir; transforming a direction by a translation does not change its direction.
    float3 dir2 = translationTransform.TransformDirection(dir);
    
    // Rotate the direction by pi/2 radians around the X axis, and back again.
    LocalTransform rotationTransform = LocalTransform.FromRotation(quaternion.RotateX(math.PI2));
    float3 dir3 = rotationTransform.TransformDirection(dir);
    // dir4 should be identical to dir, within the limits of floating-point precision
    float3 dir4 = rotationTransform.InverseTransformDirection(dir3);
    In This Article
    Back to top
    Copyright © 2026 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)