vector.Vector3
- class vector.Vector3(x: float = 0.0, y: float = 0.0, z: float = 0.0)
Class for representing points or directions in space as three float values.
A
Vector3
is an immutable object, so it’s x, y, and z properties cannot be changed, and all of its methods return newVector3
s without modifying the original.In addition to the methods documented here,
Vector3
also supports infix operators such as+
,-
between vectors,*
between a vector and afloat
when the vector occurs on the left, and unary-
equivalent to multiplying by -1.Vector3
also implements the__getitem__
method for indices0
,1
,2
. So you can access thex
,y
,z
components of a vectorv
asv[0]
,v[1]
, andv[2]
respectively. Negative values and slices work in the usual way for python iterables.Generally, methods that take in a vector also accept 3-tuples or lists of length 3.
Under the hood, this class is implemented by the Unity Engine’s Vector3 class. More documentation can be found here.
- property x: float
- property y: float
- property z: float
- magnitude() float
Returns the magnitude of the vector.
See https://docs.unity3d.com/ScriptReference/Vector3-magnitude.html.
- static normalize(v: Vector3) Vector3
Returns a normalized vector in the same direction as v.
See https://docs.unity3d.com/ScriptReference/Vector3-normalized.html.
- static dot(v: Vector3, u: Vector3) float
Returns the dot product of
v
andu
.See https://docs.unity3d.com/ScriptReference/Vector3-operator_multiply.html.
- static scale(v: Vector3, s: float) Vector3
Returns a vector equivalent to
v
scaled bys
.See https://docs.unity3d.com/ScriptReference/Vector3-operator_multiply.html.
- static cross(v: Vector3, u: Vector3) Vector3
Returns the cross product of
v
andu
.See https://docs.unity3d.com/ScriptReference/Vector3.Cross.html.
- static project_onto_vector(original: Vector3, normal: Vector3) Vector3
Returns the projection of
original
ontonormal
.See https://docs.unity3d.com/ScriptReference/Vector3.Project.html.
- static project_onto_plane(point_to_project: Vector3, plane_normal: Vector3) Vector3
Returns the projection of
point_to_project
ontoplane_normal
.See https://docs.unity3d.com/ScriptReference/Vector3.ProjectOnPlane.html.
- static lerp(start: Vector3, end: Vector3, t: float) Vector3
Returns a vector which is
t
percent of the way betweenstart
andend
.See https://docs.unity3d.com/ScriptReference/Vector3.Lerp.html.
- static angle(source: Vector3, destination: Vector3) float
Returns the angle in radians between
source
anddestination
.See https://docs.unity3d.com/ScriptReference/Vector3.Angle.html, but in radians.
- static angle_degrees(source: Vector3, destination: Vector3) float
Returns the angle in degrees between
source
anddestination
.See https://docs.unity3d.com/ScriptReference/Vector3.Angle.html.
- static clamp_magnitude(v: Vector3, length: float) Vector3
Returns a vector in the direction of
v
with magnitude ofmax(v.magnitude,length)
.See https://docs.unity3d.com/ScriptReference/Vector3.ClampMagnitude.html.
- static lerp_unclamped(start: Vector3, end: Vector3, t: float) Vector3
Returns a vector which is
t
percent of the way betweenstart
andend
. Ift
is less than0
or greater than1
, the value is extrapolated.See https://docs.unity3d.com/ScriptReference/Vector3.LerpUnclamped.html.
- static max(v: Vector3, u: Vector3) Vector3
Returns a vector equivalent to
Vector3(*[max(a,b) for a,b in zip(v,u)])
.See https://docs.unity3d.com/ScriptReference/Vector3.Max.html.
- static min(v: Vector3, u: Vector3) Vector3
Returns a vector equivalent to
Vector3(*[min(a,b) for a,b in zip(v,u)])
.See https://docs.unity3d.com/ScriptReference/Vector3.Min.html.
- static move_towards(current: Vector3, target: Vector3, max_distance: float) Vector3
Returns a vector that is as close to
target
as possible while being at mostmax_distance
far fromcurrent
.See https://docs.unity3d.com/ScriptReference/Vector3.MoveTowards.html.
- static orthonormailze(normal: Vector3, tangent: Vector3, binormal: Optional[Vector3] = None) Tuple[Vector3, Vector3, Optional[Vector3]]
Returns vectors that are orthoganal to each other and normal.
normal
will stay pointed in the same direction, but the other argument(s) may be redirected to be orthoganal to each other. Ifbinormal
is supplied, a third result will be in the returned tuple, otherwise it will be left asNone
.See https://docs.unity3d.com/ScriptReference/Vector3.OrthoNormalize.html.
- static reflect(normal: Vector3, direction: Vector3) Vector3
Returns a vector equivalent to
direction
reflected by the plane defined bynormal
.See https://docs.unity3d.com/ScriptReference/Vector3.Reflect.html.
- static rotate_towards(current: Vector3, target: Vector3, max_radians: float, max_meters: float) Vector3
Returns a vector as close to
target
as possible while keeping the angle betweencurrent
less than or equal tomax_radians
and its difference in magnitude less than or equal tomax_meters
.See https://docs.unity3d.com/ScriptReference/Vector3.RotateTowards.html.
- static pairswise_scale(v: Vector3, u: Vector3) Vector3
Returns a vector equivalent to
Vector3(*[a * b for a,b in zip(v,u)])
See https://docs.unity3d.com/ScriptReference/Vector3.Scale.html.
- static signed_angle(source: Vector3, destination: Vector3, axis: Vector3) float
Returns the angle in radians between
source
anddestination
usingaxis
andcross()
to determine the sign.See https://docs.unity3d.com/ScriptReference/Vector3.SignedAngle.html.
- static slerp(v: Vector3, u: Vector3, t: float) Vector3
Returns the spherical interpolation between
v
andu
byt
.See https://docs.unity3d.com/ScriptReference/Vector3.Slerp.html.
- static slerp_unclamped(v: Vector3, u: Vector3, t: float) Vector3
Returns the unclamped spherical interpolation between
v
andu
byt
.See https://docs.unity3d.com/ScriptReference/Vector3.SlerpUnclamped.html.
- static euler_angles_from_rotation_axis(axis: Vector3) Vector3
Decomposes a rotation around an axis (with magnitude in radians) into three axis aligned rotations ordered z then x then y, known as euler angles.