docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Struct Vector3<C>

    A three-component vector whose components are expressed in coordinate space C.

    Implements
    IEquatable<Vector3<C>>
    IFormattable
    Inherited Members
    object.Equals(object, object)
    object.GetType()
    object.ReferenceEquals(object, object)
    Namespace: Unity.SimulationPro.Foundation
    Assembly: Unity.SimulationPro.Foundation.dll
    Syntax
    [Serializable]
    public struct Vector3<C> : IEquatable<Vector3<C>>, IFormattable where C : ICoordinateSpace, new()
    Type Parameters
    Name Description
    C

    The coordinate space type. Must implement ICoordinateSpace and have a public parameterless constructor. Built-in options: RUF, FLU, FRD, NED, ENU, NEDLocal, ENULocal.

    Remarks

    Construct from a Unity Vector3 (RUF) using new Vector3<C>(unityVector) — the conversion to frame C is applied automatically.

    Retrieve the Unity equivalent via toUnity. The struct is assignment-compatible with PointMsg, Point32Msg, and Vector3Msg via implicit conversion.

    Constructors

    Vector3(float, float, float)

    Initializes a new Vector3<C> from raw components already in space C. No coordinate conversion is applied.

    Declaration
    public Vector3(float x, float y, float z)
    Parameters
    Type Name Description
    float x

    X-axis component.

    float y

    Y-axis component.

    float z

    Z-axis component.

    Vector3(Vector3)

    Initializes a new Vector3<C> by converting a Unity (RUF) vector into coordinate space C.

    Declaration
    public Vector3(Vector3 vec_ruf)
    Parameters
    Type Name Description
    Vector3 vec_ruf

    The vector in Unity (RUF) space.

    Properties

    back

    Gets the back direction (Unity Z-) expressed in coordinate space C.

    Declaration
    public static Vector3<C> back { get; }
    Property Value
    Type Description
    Vector3<C>

    down

    Gets the down direction (Unity Y-) expressed in coordinate space C.

    Declaration
    public static Vector3<C> down { get; }
    Property Value
    Type Description
    Vector3<C>

    forward

    Gets the forward direction (Unity Z+) expressed in coordinate space C.

    Declaration
    public static Vector3<C> forward { get; }
    Property Value
    Type Description
    Vector3<C>

    left

    Gets the left direction (Unity X-) expressed in coordinate space C.

    Declaration
    public static Vector3<C> left { get; }
    Property Value
    Type Description
    Vector3<C>

    magnitude

    Gets the length of this vector.

    Declaration
    public float magnitude { get; }
    Property Value
    Type Description
    float

    negativeInfinity

    Gets a vector with all components set to negative infinity in space C.

    Declaration
    public static Vector3<C> negativeInfinity { get; }
    Property Value
    Type Description
    Vector3<C>

    normalized

    Gets the unit-length version of this vector in space C.

    Declaration
    public Vector3<C> normalized { get; }
    Property Value
    Type Description
    Vector3<C>

    one

    Gets the vector (1, 1, 1) in raw space C (no coordinate conversion).

    Declaration
    public static Vector3<C> one { get; }
    Property Value
    Type Description
    Vector3<C>

    positiveInfinity

    Gets a vector with all components set to positive infinity in space C.

    Declaration
    public static Vector3<C> positiveInfinity { get; }
    Property Value
    Type Description
    Vector3<C>

    right

    Gets the right direction (Unity X+) expressed in coordinate space C.

    Declaration
    public static Vector3<C> right { get; }
    Property Value
    Type Description
    Vector3<C>

    sqrMagnitude

    Gets the squared length of this vector.

    Declaration
    public float sqrMagnitude { get; }
    Property Value
    Type Description
    float

    toUnity

    Gets the equivalent Unity (RUF) Vector3 by converting from space C.

    Declaration
    public Vector3 toUnity { get; }
    Property Value
    Type Description
    Vector3

    toUnityAngularVelocity

    Gets the equivalent Unity (RUF) angular velocity by converting from space C.

    Declaration
    public Vector3 toUnityAngularVelocity { get; }
    Property Value
    Type Description
    Vector3

    up

    Gets the up direction (Unity Y+) expressed in coordinate space C.

    Declaration
    public static Vector3<C> up { get; }
    Property Value
    Type Description
    Vector3<C>

    x

    Gets or sets the X component in coordinate space C.

    Declaration
    public float x { get; set; }
    Property Value
    Type Description
    float

    y

    Gets or sets the Y component in coordinate space C.

    Declaration
    public float y { get; set; }
    Property Value
    Type Description
    float

    z

    Gets or sets the Z component in coordinate space C.

    Declaration
    public float z { get; set; }
    Property Value
    Type Description
    float

    zero

    Gets the zero vector in space C.

    Declaration
    public static Vector3<C> zero { get; }
    Property Value
    Type Description
    Vector3<C>

    Methods

    Angle(Vector3<C>, Vector3<C>)

    Returns the angle in degrees between two vectors in space C.

    Declaration
    public static float Angle(Vector3<C> from, Vector3<C> to)
    Parameters
    Type Name Description
    Vector3<C> from

    The starting direction vector.

    Vector3<C> to

    The ending direction vector.

    Returns
    Type Description
    float

    The unsigned angle in degrees between from and to.

    ClampMagnitude(Vector3<C>, float)

    Returns a copy of vector clamped to maxLength.

    Declaration
    public static Vector3<C> ClampMagnitude(Vector3<C> vector, float maxLength)
    Parameters
    Type Name Description
    Vector3<C> vector

    A 3D direction vector.

    float maxLength

    Maximum allowed magnitude for the resulting vector.

    Returns
    Type Description
    Vector3<C>

    The vector with its magnitude clamped to maxLength.

    Cross(Vector3<C>, Vector3<C>)

    Returns the cross product of two vectors in space C.

    Declaration
    public static Vector3<C> Cross(Vector3<C> lhs, Vector3<C> rhs)
    Parameters
    Type Name Description
    Vector3<C> lhs

    Left-hand side operand.

    Vector3<C> rhs

    Right-hand side operand.

    Returns
    Type Description
    Vector3<C>

    A vector perpendicular to both lhs and rhs.

    Distance(Vector3<C>, Vector3<C>)

    Returns the distance between two points in space C.

    Declaration
    public static float Distance(Vector3<C> a, Vector3<C> b)
    Parameters
    Type Name Description
    Vector3<C> a

    First operand.

    Vector3<C> b

    Second operand.

    Returns
    Type Description
    float

    The Euclidean distance between a and b.

    Dot(Vector3<C>, Vector3<C>)

    Returns the dot product of two vectors in space C.

    Declaration
    public static float Dot(Vector3<C> lhs, Vector3<C> rhs)
    Parameters
    Type Name Description
    Vector3<C> lhs

    Left-hand side operand.

    Vector3<C> rhs

    Right-hand side operand.

    Returns
    Type Description
    float

    The scalar dot product of lhs and rhs.

    Equals(object)

    Declaration
    public override bool Equals(object other)
    Parameters
    Type Name Description
    object other
    Returns
    Type Description
    bool
    Overrides
    ValueType.Equals(object)

    Equals(Vector3<C>)

    Declaration
    public bool Equals(Vector3<C> other)
    Parameters
    Type Name Description
    Vector3<C> other
    Returns
    Type Description
    bool

    FromUnityAngularVelocity(Vector3)

    Creates a Vector3<C> from a Unity (RUF) angular velocity, applying the angular-velocity conversion for space C.

    Declaration
    public static Vector3<C> FromUnityAngularVelocity(Vector3 angularVelocityRUF)
    Parameters
    Type Name Description
    Vector3 angularVelocityRUF

    The angular velocity in Unity (RUF) space.

    Returns
    Type Description
    Vector3<C>

    The angular velocity expressed in coordinate space C.

    GetHashCode()

    Declaration
    public override int GetHashCode()
    Returns
    Type Description
    int
    Overrides
    ValueType.GetHashCode()

    Lerp(Vector3<C>, Vector3<C>, float)

    Linearly interpolates between two vectors in space C with t clamped to [0,1].

    Declaration
    public static Vector3<C> Lerp(Vector3<C> a, Vector3<C> b, float t)
    Parameters
    Type Name Description
    Vector3<C> a

    First operand.

    Vector3<C> b

    Second operand.

    float t

    Interpolation factor, typically in the range [0, 1].

    Returns
    Type Description
    Vector3<C>

    The interpolated vector between a and b.

    LerpUnclamped(Vector3<C>, Vector3<C>, float)

    Linearly interpolates between two vectors in space C without clamping t.

    Declaration
    public static Vector3<C> LerpUnclamped(Vector3<C> a, Vector3<C> b, float t)
    Parameters
    Type Name Description
    Vector3<C> a

    First operand.

    Vector3<C> b

    Second operand.

    float t

    Interpolation factor, typically in the range [0, 1].

    Returns
    Type Description
    Vector3<C>

    The interpolated vector between a and b.

    Magnitude(Vector3<C>)

    Returns the length of the given vector.

    Declaration
    public static float Magnitude(Vector3<C> vector)
    Parameters
    Type Name Description
    Vector3<C> vector

    The vector whose magnitude is computed.

    Returns
    Type Description
    float

    The magnitude (length) of vector.

    Max(Vector3<C>, Vector3<C>)

    Returns a vector whose components are the per-component maximum of lhs and rhs.

    Declaration
    public static Vector3<C> Max(Vector3<C> lhs, Vector3<C> rhs)
    Parameters
    Type Name Description
    Vector3<C> lhs

    Left-hand side operand.

    Vector3<C> rhs

    Right-hand side operand.

    Returns
    Type Description
    Vector3<C>

    A vector with the largest X, Y, and Z from either input.

    Min(Vector3<C>, Vector3<C>)

    Returns a vector whose components are the per-component minimum of lhs and rhs.

    Declaration
    public static Vector3<C> Min(Vector3<C> lhs, Vector3<C> rhs)
    Parameters
    Type Name Description
    Vector3<C> lhs

    Left-hand side operand.

    Vector3<C> rhs

    Right-hand side operand.

    Returns
    Type Description
    Vector3<C>

    A vector with the smallest X, Y, and Z from either input.

    MoveTowards(Vector3<C>, Vector3<C>, float)

    Moves current towards target by at most maxDistanceDelta.

    Declaration
    public static Vector3<C> MoveTowards(Vector3<C> current, Vector3<C> target, float maxDistanceDelta)
    Parameters
    Type Name Description
    Vector3<C> current

    The current position.

    Vector3<C> target

    The position to move towards.

    float maxDistanceDelta

    Maximum distance to move per step.

    Returns
    Type Description
    Vector3<C>

    A vector moved from current towards target.

    Normalize()

    Normalizes this vector in-place to unit length.

    Declaration
    public void Normalize()

    Normalize(Vector3<C>)

    Returns the normalized (unit-length) form of value.

    Declaration
    public static Vector3<C> Normalize(Vector3<C> value)
    Parameters
    Type Name Description
    Vector3<C> value

    The vector to normalize.

    Returns
    Type Description
    Vector3<C>

    A unit-length vector in the same direction as value, or zero if the input has zero length.

    OrthoNormalize(ref Vector3<C>, ref Vector3<C>)

    Orthonormalizes two vectors in-place using the Gram-Schmidt process.

    Declaration
    public static void OrthoNormalize(ref Vector3<C> normal, ref Vector3<C> tangent)
    Parameters
    Type Name Description
    Vector3<C> normal

    The primary vector; will be normalized.

    Vector3<C> tangent

    The secondary vector; will be made orthogonal to normal and normalized.

    OrthoNormalize(ref Vector3<C>, ref Vector3<C>, ref Vector3<C>)

    Orthonormalizes three vectors in-place using the Gram-Schmidt process.

    Declaration
    public static void OrthoNormalize(ref Vector3<C> normal, ref Vector3<C> tangent, ref Vector3<C> binormal)
    Parameters
    Type Name Description
    Vector3<C> normal

    The primary vector; will be normalized.

    Vector3<C> tangent

    The secondary vector; will be made orthogonal to normal and normalized.

    Vector3<C> binormal

    The tertiary vector; will be made orthogonal to both others and normalized.

    Project(Vector3<C>, Vector3<C>)

    Projects vector onto onNormal.

    Declaration
    public static Vector3<C> Project(Vector3<C> vector, Vector3<C> onNormal)
    Parameters
    Type Name Description
    Vector3<C> vector

    The vector to project.

    Vector3<C> onNormal

    The direction to project onto.

    Returns
    Type Description
    Vector3<C>

    The component of vector along onNormal.

    ProjectOnPlane(Vector3<C>, Vector3<C>)

    Projects vector onto a plane defined by planeNormal.

    Declaration
    public static Vector3<C> ProjectOnPlane(Vector3<C> vector, Vector3<C> planeNormal)
    Parameters
    Type Name Description
    Vector3<C> vector

    The vector to project.

    Vector3<C> planeNormal

    The normal of the plane to project onto.

    Returns
    Type Description
    Vector3<C>

    The component of vector that lies in the plane.

    Reflect(Vector3<C>, Vector3<C>)

    Reflects inDirection off the plane defined by inNormal.

    Declaration
    public static Vector3<C> Reflect(Vector3<C> inDirection, Vector3<C> inNormal)
    Parameters
    Type Name Description
    Vector3<C> inDirection

    Input direction vector.

    Vector3<C> inNormal

    Surface normal for reflection.

    Returns
    Type Description
    Vector3<C>

    The reflected direction vector.

    RotateTowards(Vector3<C>, Vector3<C>, float, float)

    Rotates current towards target by the specified angular and magnitude deltas.

    Declaration
    public static Vector3<C> RotateTowards(Vector3<C> current, Vector3<C> target, float maxRadiansDelta, float maxMagnitudeDelta)
    Parameters
    Type Name Description
    Vector3<C> current

    The current direction vector.

    Vector3<C> target

    The target direction vector to rotate towards.

    float maxRadiansDelta

    Maximum rotation step in radians.

    float maxMagnitudeDelta

    Maximum change in vector magnitude per step.

    Returns
    Type Description
    Vector3<C>

    A vector rotated from current towards target.

    Scale(Vector3<C>)

    Scales this vector component-wise by scale.

    Declaration
    public void Scale(Vector3<C> scale)
    Parameters
    Type Name Description
    Vector3<C> scale

    Scale factor along each axis.

    Scale(Vector3<C>, Vector3<C>)

    Returns the per-component product of two vectors.

    Declaration
    public static Vector3<C> Scale(Vector3<C> a, Vector3<C> b)
    Parameters
    Type Name Description
    Vector3<C> a

    First operand.

    Vector3<C> b

    Second operand.

    Returns
    Type Description
    Vector3<C>

    A vector with each component equal to the product of the corresponding components of a and b.

    Set(float, float, float)

    Sets the X, Y, and Z components of this vector.

    Declaration
    public void Set(float newX, float newY, float newZ)
    Parameters
    Type Name Description
    float newX

    New X component value.

    float newY

    New Y component value.

    float newZ

    New Z component value.

    SignedAngle(Vector3<C>, Vector3<C>, Vector3<C>)

    Returns the signed angle in degrees from from to to around axis.

    Declaration
    public static float SignedAngle(Vector3<C> from, Vector3<C> to, Vector3<C> axis)
    Parameters
    Type Name Description
    Vector3<C> from

    The starting direction vector.

    Vector3<C> to

    The ending direction vector.

    Vector3<C> axis

    The reference axis used to determine the sign of the angle.

    Returns
    Type Description
    float

    The signed angle in degrees, positive for counter-clockwise rotation around axis.

    Slerp(Vector3<C>, Vector3<C>, float)

    Spherically interpolates between two vectors with t clamped to [0,1].

    Declaration
    public static Vector3<C> Slerp(Vector3<C> a, Vector3<C> b, float t)
    Parameters
    Type Name Description
    Vector3<C> a

    First operand.

    Vector3<C> b

    Second operand.

    float t

    Interpolation factor, typically in the range [0, 1].

    Returns
    Type Description
    Vector3<C>

    The spherically interpolated vector between a and b.

    SlerpUnclamped(Vector3<C>, Vector3<C>, float)

    Spherically interpolates between two vectors without clamping t.

    Declaration
    public static Vector3<C> SlerpUnclamped(Vector3<C> a, Vector3<C> b, float t)
    Parameters
    Type Name Description
    Vector3<C> a

    First operand.

    Vector3<C> b

    Second operand.

    float t

    Interpolation factor, typically in the range [0, 1].

    Returns
    Type Description
    Vector3<C>

    The spherically interpolated vector between a and b.

    SmoothDamp(Vector3<C>, Vector3<C>, ref Vector3<C>, float)

    Gradually moves current towards target using a spring-damper function.

    Declaration
    public static Vector3<C> SmoothDamp(Vector3<C> current, Vector3<C> target, ref Vector3<C> currentVelocity, float smoothTime)
    Parameters
    Type Name Description
    Vector3<C> current

    The current position.

    Vector3<C> target

    The position to move towards.

    Vector3<C> currentVelocity

    Current velocity; modified by the method each call.

    float smoothTime

    Approximate time in seconds to reach the target.

    Returns
    Type Description
    Vector3<C>

    The smoothly damped vector approaching target.

    SmoothDamp(Vector3<C>, Vector3<C>, ref Vector3<C>, float, float)

    Gradually moves current towards target with a maximum speed.

    Declaration
    public static Vector3<C> SmoothDamp(Vector3<C> current, Vector3<C> target, ref Vector3<C> currentVelocity, float smoothTime, float maxSpeed)
    Parameters
    Type Name Description
    Vector3<C> current

    The current position.

    Vector3<C> target

    The position to move towards.

    Vector3<C> currentVelocity

    Current velocity; modified by the method each call.

    float smoothTime

    Approximate time in seconds to reach the target.

    float maxSpeed

    Maximum speed cap for the interpolation.

    Returns
    Type Description
    Vector3<C>

    The smoothly damped vector approaching target.

    SqrMagnitude(Vector3<C>)

    Returns the squared length of the given vector.

    Declaration
    public static float SqrMagnitude(Vector3<C> vector)
    Parameters
    Type Name Description
    Vector3<C> vector

    The vector whose squared magnitude is computed.

    Returns
    Type Description
    float

    The squared magnitude of vector.

    ToString()

    Declaration
    public override string ToString()
    Returns
    Type Description
    string
    Overrides
    ValueType.ToString()

    ToString(string)

    Declaration
    public string ToString(string format)
    Parameters
    Type Name Description
    string format
    Returns
    Type Description
    string

    ToString(string, IFormatProvider)

    Declaration
    public string ToString(string format, IFormatProvider formatProvider)
    Parameters
    Type Name Description
    string format
    IFormatProvider formatProvider
    Returns
    Type Description
    string

    To<C2>()

    Converts this vector to another coordinate space C2 by round-tripping through Unity (RUF).

    Declaration
    public Vector3<C2> To<C2>() where C2 : ICoordinateSpace, new()
    Returns
    Type Description
    Vector3<C2>

    The equivalent vector in space C2.

    Type Parameters
    Name Description
    C2

    The target coordinate space.

    Operators

    operator +(Vector3<C>, Vector3<C>)

    Adds two vectors component-wise.

    Declaration
    public static Vector3<C> operator +(Vector3<C> a, Vector3<C> b)
    Parameters
    Type Name Description
    Vector3<C> a

    The first vector.

    Vector3<C> b

    The second vector.

    Returns
    Type Description
    Vector3<C>

    The component-wise sum of a and b.

    operator /(Vector3<C>, float)

    Divides all components by a scalar.

    Declaration
    public static Vector3<C> operator /(Vector3<C> a, float d)
    Parameters
    Type Name Description
    Vector3<C> a

    The vector to divide.

    float d

    The scalar divisor.

    Returns
    Type Description
    Vector3<C>

    A vector with each component divided by d.

    operator ==(Vector3<C>, Vector3<C>)

    Returns true when both vectors have the same components.

    Declaration
    public static bool operator ==(Vector3<C> lhs, Vector3<C> rhs)
    Parameters
    Type Name Description
    Vector3<C> lhs

    The left-hand vector.

    Vector3<C> rhs

    The right-hand vector.

    Returns
    Type Description
    bool

    true if the vectors are approximately equal; otherwise false.

    explicit operator Vector3(Vector3<C>)

    Explicitly converts a Vector3<C> to a Unity (RUF) Vector3.

    Declaration
    public static explicit operator Vector3(Vector3<C> vec)
    Parameters
    Type Name Description
    Vector3<C> vec

    The typed vector to convert.

    Returns
    Type Description
    Vector3

    The equivalent Unity (RUF) vector.

    explicit operator Vector3<C>(Vector3)

    Explicitly converts a Unity (RUF) Vector3 to a Vector3<C>.

    Declaration
    public static explicit operator Vector3<C>(Vector3 vec)
    Parameters
    Type Name Description
    Vector3 vec

    The Unity vector to convert.

    Returns
    Type Description
    Vector3<C>

    The vector in coordinate space C.

    implicit operator Point32Msg(Vector3<C>)

    Implicitly converts a Vector3<C> to a Point32Msg using its raw components.

    Declaration
    public static implicit operator Point32Msg(Vector3<C> rvec)
    Parameters
    Type Name Description
    Vector3<C> rvec

    The typed vector to convert.

    Returns
    Type Description
    Point32Msg

    A Point32Msg with the same X, Y, and Z values.

    implicit operator PointMsg(Vector3<C>)

    Implicitly converts a Vector3<C> to a PointMsg using its raw components.

    Declaration
    public static implicit operator PointMsg(Vector3<C> rvec)
    Parameters
    Type Name Description
    Vector3<C> rvec

    The typed vector to convert.

    Returns
    Type Description
    PointMsg

    A PointMsg with the same X, Y, and Z values.

    implicit operator Vector3Msg(Vector3<C>)

    Implicitly converts a Vector3<C> to a Vector3Msg using its raw components.

    Declaration
    public static implicit operator Vector3Msg(Vector3<C> rvec)
    Parameters
    Type Name Description
    Vector3<C> rvec

    The typed vector to convert.

    Returns
    Type Description
    Vector3Msg

    A Vector3Msg with the same X, Y, and Z values.

    operator !=(Vector3<C>, Vector3<C>)

    Returns true when the vectors differ in at least one component.

    Declaration
    public static bool operator !=(Vector3<C> lhs, Vector3<C> rhs)
    Parameters
    Type Name Description
    Vector3<C> lhs

    The left-hand vector.

    Vector3<C> rhs

    The right-hand vector.

    Returns
    Type Description
    bool

    true if the vectors are not approximately equal; otherwise false.

    operator *(float, Vector3<C>)

    Multiplies all components by a scalar (scalar on the left).

    Declaration
    public static Vector3<C> operator *(float d, Vector3<C> a)
    Parameters
    Type Name Description
    float d

    The scalar multiplier.

    Vector3<C> a

    The vector to scale.

    Returns
    Type Description
    Vector3<C>

    A vector with each component multiplied by d.

    operator *(Vector3<C>, float)

    Multiplies all components by a scalar (scalar on the right).

    Declaration
    public static Vector3<C> operator *(Vector3<C> a, float d)
    Parameters
    Type Name Description
    Vector3<C> a

    The vector to scale.

    float d

    The scalar multiplier.

    Returns
    Type Description
    Vector3<C>

    A vector with each component multiplied by d.

    operator -(Vector3<C>, Vector3<C>)

    Subtracts two vectors component-wise.

    Declaration
    public static Vector3<C> operator -(Vector3<C> a, Vector3<C> b)
    Parameters
    Type Name Description
    Vector3<C> a

    The vector to subtract from.

    Vector3<C> b

    The vector to subtract.

    Returns
    Type Description
    Vector3<C>

    The component-wise difference of a minus b.

    operator -(Vector3<C>)

    Negates all components of the vector.

    Declaration
    public static Vector3<C> operator -(Vector3<C> a)
    Parameters
    Type Name Description
    Vector3<C> a

    The vector to negate.

    Returns
    Type Description
    Vector3<C>

    A vector with each component negated.

    Implements

    IEquatable<T>
    IFormattable
    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)