12 public static Vector2
Clone(
this Vector2 v)
14 return new Vector2(v.x, v.y);
22 public static Vector2
WithX(
this Vector2 v,
float x = 0f)
24 return new Vector2(x, v.y);
32 public static Vector2
WithY(
this Vector2 v,
float y = 0f)
34 return new Vector2(v.x, y);
44 return new Vector3(x, v.x, v.y);
54 return new Vector3(v.x, y, v.y);
64 return new Vector3(v.x, v.y, z);
71 public static Vector3
Clone(
this Vector3 v)
73 return new Vector3(v.x, v.y, v.z);
82 return new Vector2(v.y, v.z);
91 return new Vector2(v.x, v.z);
100 return new Vector2(v.x, v.y);
108 public static Vector3
WithX(
this Vector3 v,
float x = 0f)
110 return new Vector3(x, v.y, v.z);
118 public static Vector3
WithY(
this Vector3 v,
float y = 0f)
120 return new Vector3(v.x, y, v.z);
128 public static Vector3
WithZ(
this Vector3 v,
float z = 0f)
130 return new Vector3(v.x, v.y, z);
141 bool clampInsideLineLength =
true)
144 Vector3 direction = (end - origin);
145 direction.Normalize();
147 Vector3 lhs = point - origin;
148 float dotP = Vector3.Dot(lhs, direction);
150 if (clampInsideLineLength)
152 float magnitudeMax = direction.magnitude;
153 dotP = Mathf.Clamp(dotP, 0f, magnitudeMax);
156 return origin + direction * dotP;
164 public static Vector3Int
ToVectorInt(
this Vector3 v,
bool round =
false)
167 return new Vector3Int(Mathf.RoundToInt(v.x), Mathf.RoundToInt(v.y), Mathf.RoundToInt(v.z));
168 return new Vector3Int((
int) v.x, (
int) v.y, (
int) v.z);
176 public static Vector2Int
ToVectorInt(
this Vector2 v,
bool round =
false)
179 return new Vector2Int(Mathf.RoundToInt(v.x), Mathf.RoundToInt(v.y));
180 return new Vector2Int((
int) v.x, (
int) v.y);
static Vector2 WithX(this Vector2 v, float x=0f)
Creates a new vector with the same value for the 'y' parameter but a new one for the 'x'.
static Vector3 ToVector3NewY(this Vector2 v, float y=0f)
Creates a new Vector3 keeping the values from the 'x' and 'y' parameters of the original Vector2 in t...
static Vector3 ToVector3NewZ(this Vector2 v, float z=0f)
Creates a new Vector3 keeping the values from the 'x' and 'y' parameters of the original Vector2 in t...
static Vector2 ToVector2WithoutY(this Vector3 v)
Creates a new Vector2 keeping the values from the 'x' and 'z' parameters of the original Vector3.
static Vector3 WithZ(this Vector3 v, float z=0f)
Creates a new vector with the same value for the 'x' and 'y' parameter but a new one for the 'z'.
static Vector3 Clone(this Vector3 v)
Creates a new vector with the same values as the original.
static Vector3Int ToVectorInt(this Vector3 v, bool round=false)
Creates a new Vector3Int with the values in the original vector.
static Vector3 ToVector3NewX(this Vector2 v, float x=0f)
Creates a new Vector3 keeping the values from the 'x' and 'y' parameters of the original Vector2 in t...
static Vector3 WithY(this Vector3 v, float y=0f)
Creates a new vector with the same value for the 'x' and 'z' parameter but a new one for the 'y'.
static Vector3 WithX(this Vector3 v, float x=0f)
Creates a new vector with the same value for the 'y' and 'z' parameter but a new one for the 'x'.
static Vector3 NearestPointOnLine(this Vector3 point, Vector3 origin, Vector3 end, bool clampInsideLineLength=true)
Calculates the nearest position in a given line or segment.
static Vector2 ToVector2WithoutX(this Vector3 v)
Creates a new Vector2 keeping the values from the 'y' and 'z' parameters of the original Vector3.
static Vector2 ToVector2WithoutZ(this Vector3 v)
Creates a new Vector2 keeping the values from the 'x' and 'y' parameters of the original Vector3.
static Vector2 Clone(this Vector2 v)
Creates a new vector with the same values as the original.
static Vector2Int ToVectorInt(this Vector2 v, bool round=false)
Creates a new Vector2Int with the values in the original vector.
static Vector2 WithY(this Vector2 v, float y=0f)
Creates a new vector with the same value for the 'x' parameter but a new one for the 'y'.