Godot Nature of Code  1.2.0
Nature of Code implemented in Godot Engine
Static Public Member Functions | List of all members
VectorExtensions Class Reference

Vector extension methods More...

Static Public Member Functions

static Vector2 NormalizeTo (this Vector2 vector, float length)
 Normalize a vector using a specific length. More...
 
static Vector2 Jitter (this Vector2 vector, float coef)
 Add a random value to X and Y components. More...
 
static Vector2 GetNormalPoint (this Vector2 p, Vector2 a, Vector2 b)
 Get a normal point on AB from P. More...
 

Detailed Description

Vector extension methods

Definition at line 6 of file VectorExtensions.cs.

Member Function Documentation

◆ GetNormalPoint()

static Vector2 VectorExtensions.GetNormalPoint ( this Vector2  p,
Vector2  a,
Vector2  b 
)
inlinestatic

Get a normal point on AB from P.

Parameters
pCurrent vector
aStart point
bEnd point
Returns
Normal point

Definition at line 48 of file VectorExtensions.cs.

49  {
50  var ap = p - a;
51  var ab = (b - a).Normalized();
52  var dot = ap.Dot(ab);
53  return a + (ab * dot);
54  }

◆ Jitter()

static Vector2 VectorExtensions.Jitter ( this Vector2  vector,
float  coef 
)
inlinestatic

Add a random value to X and Y components.

Parameters
vectorCurrent vector
coefCoefficient
Returns
Vector with jitter

Definition at line 33 of file VectorExtensions.cs.

34  {
35  var vec = new Vector2(vector.x, vector.y);
36  vec.x += MathUtils.Randf() * coef;
37  vec.y += MathUtils.Randf() * coef;
38  return vec;
39  }
Math utility functions
Definition: MathUtils.cs:7
static float Randf()
Return a random floating number between 0 and 1.
Definition: MathUtils.cs:26

◆ NormalizeTo()

static Vector2 VectorExtensions.NormalizeTo ( this Vector2  vector,
float  length 
)
inlinestatic

Normalize a vector using a specific length.

Parameters
vectorCurrent vector
lengthTarget length
Returns
Normalized vector

Definition at line 14 of file VectorExtensions.cs.

15  {
16  var vec = new Vector2(vector.x, vector.y);
17  var len = vec.Length();
18  if (len > 0)
19  {
20  len /= length;
21  vec.x *= len;
22  vec.y *= len;
23  }
24  return vec;
25  }

The documentation for this class was generated from the following file: