# SVector

**الأعضاء** 33

|       |                                   |                                                                                                                 |
| ----- | --------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| دالة  | [Add](#add)                       | Adds this Vector                                                                                                |
| دالة  | [Scale](#scale)                   | Multiplies this Vector                                                                                          |
| دالة  | [Divide](#divide)                 | Divides this Vector                                                                                             |
| دالة  | [Distance](#distance)             | Returns the distance between this vector and other in meters                                                    |
| دالة  | [SquareDistance](#squaredistance) | Returns the square of the distance between this vector and other in meters, considerably faster than distance() |
| دالة  | [InRange](#inrange)               | Returns if other is within range meters of this vector, inclusive                                               |
| دالة  | [Cross](#cross)                   | Returns the cross product of this vector and other                                                              |
| دالة  | [Lerp](#lerp)                     | Linear interpolates between this and other based on factor t (0-1)                                              |
| دالة  | [Slerp](#slerp)                   | Spherically linear interpolates between this and other based on factor t (0-1)                                  |
| دالة  | [MoveTowards](#movetowards)       | Moves this vector closer to other by a maximum of maxDistance units                                             |
| دالة  | [Dot](#dot)                       | Returns the dot product between this and other (note - normalise your vectors first!                            |
| دالة  | [Equals](#equals)                 | –                                                                                                               |
| دالة  | [ToString](#tostring)             | –                                                                                                               |
| دالة  | [New](#new)                       | Initialises vector from three floats                                                                            |
| دالة  | [operator+](#operator)            | –                                                                                                               |
| دالة  | [operator-](#operator-)           | –                                                                                                               |
| دالة  | [operator\*](#operator-1)         | –                                                                                                               |
| دالة  | [operator/](#operator-2)          | –                                                                                                               |
| خاصية | [X](#x)                           | X axis (red axis)                                                                                               |
| خاصية | [Y](#y)                           | Y axis (green axis)                                                                                             |
| خاصية | [Z](#z)                           | Z axis (blue axis)                                                                                              |
| خاصية | [Magnitude](#magnitude)           | Returns the magnitude of this vector                                                                            |
| خاصية | [Normalised](#normalised)         | Returns the normalised version of this vector                                                                   |
| خاصية | [Up](#up)                         | Equivalent of new SVector(0,1,0)                                                                                |
| خاصية | [Down](#down)                     | Equivalent of new SVector(0,-1,0)                                                                               |
| خاصية | [Left](#left)                     | Equivalent of new SVector(-1,0,0)                                                                               |
| خاصية | [Right](#right)                   | Equivalent of new SVector(1,0,0)                                                                                |
| خاصية | [Forward](#forward)               | Equivalent of new SVector(0,0,1)                                                                                |
| خاصية | [Back](#back)                     | Equivalent of new SVector(0,0,-1)                                                                               |
| خاصية | [Zero](#zero)                     | Equivalent of new SVector(0,0,0)                                                                                |
| خاصية | [One](#one)                       | Equivalent of new SVector(1,1,1)                                                                                |
| خاصية | [MaxValue](#maxvalue)             | Contains the largest possible vector \[3.402823E+38, 3.402823E+38, 3.402823E+38]                                |
| خاصية | [MinValue](#minvalue)             | Contains the largest possible negative vector                                                                   |

## الدوال

### Add

SVector Add(SVector other)

SVector Add(float other)

Adds this Vector

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| other | SVector | –                 |
| other | float   | –                 |

القيم المرجعة

`SVector`

مثال

**Lua**

```lua
local vector = Vector.New(0, 10, 0);
local vectorOther = Vector.New(40, 50, 6);
Space.Log(vector.Add(vectorOther));
-- prints [40, 60, 6]

Space.Log(vector + vectorOther);
-- prints [40, 60, 6]

```

**Lua**

```lua
local vectorB = Vector.New(0, 10, 0);
Space.Log(vectorB.Add(5));
-- prints [5, 15, 5]

```

### Scale

SVector Scale(SVector other)

SVector Scale(float other)

Multiplies this Vector

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| other | SVector | –                 |
| other | float   | –                 |

القيم المرجعة

`SVector`

مثال

**Lua**

```lua
local vector = Vector.New(0, 10, 0);
local vectorOther = Vector.New(2, 5, 4);
Space.Log(vector.Scale(vectorOther));
-- prints [0, 50, 0]

Space.Log(vector * vectorOther);
-- prints [0, 50, 0]

```

**Lua**

```lua
local vector = Vector.New(0, 10, 0);
Space.Log(vector.Scale(5));
-- prints [0, 50, 0]

Space.Log(vector * 5);
-- prints [0, 50, 0]

```

### Divide

SVector Divide(SVector other)

SVector Divide(float other)

Divides this Vector

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| other | SVector | –                 |
| other | float   | –                 |

القيم المرجعة

`SVector`

مثال

**Lua**

```lua
local vector = Vector.New(10, 10, 10);
local vectorOther = Vector.New(2, 2, 2);
Space.Log(vector.Divide(vectorOther));
-- prints [5, 5, 5]

Space.Log(vector / vectorOther);
-- prints [5, 5, 5]

```

**Lua**

```lua
local vector = Vector.New(10, 10, 10);
Space.Log(vector.Divide(2));
-- prints [5, 5, 5]

Space.Log(vector / 2);
-- prints [5, 5, 5]

```

### Distance

float Distance(SVector other)

Returns the distance between this vector and other in meters

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| other | SVector | –                 |

القيم المرجعة

`float`

مثال

**Lua**

```lua
local vector = Vector.New(3, 3, 3.5);
local vectorOther = Vector.New(2, 2, 2);
Space.Log(vector.Distance(vectorOther));
-- prints 2.06155276298523

```

**Lua**

```lua
--the below script will change the objects color to green if you are near the object 
--and change color to red if you are far from the object 

thisGameObject = Space.Host.ExecutingObject

function OnUpdate()
  positionAvatar = Space.Scene.PlayerAvatar.GameObject.WorldPosition
  positionObject = thisGameObject.WorldPosition
  
     if positionAvatar.Distance(positionObject) < 5 then
         thisGameObject.Renderer.Material.SetColor("_Color",0,1,0,1)
      else
         thisGameObject.Renderer.Material.SetColor("_Color",1,0,0,1)
      end
  
end  

thisGameObject.OnUpdate(OnUpdate)

```

### SquareDistance

float SquareDistance(SVector other)

Returns the square of the distance between this vector and other in meters, considerably faster than distance()

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| other | SVector | –                 |

القيم المرجعة

`float`

مثال

**Lua**

```lua
local vector = Vector.New(3, 3, 3.5);
local vectorOther = Vector.New(2, 2, 2);
Space.Log(vector.SquareDistance(vectorOther));
-- prints 4.25

```

**Lua**

```lua
--the below script will change the objects color to green if you are near the object 
--and change color to red if you are far from the object 

thisGameObject = Space.Host.ExecutingObject

function OnUpdate()
  positionAvatar = Space.Scene.PlayerAvatar.GameObject.WorldPosition
  positionObject = thisGameObject.WorldPosition
  
     if positionAvatar.SquareDistance(positionObject) < 25 then
         thisGameObject.Renderer.Material.SetColor("_Color",0,1,0,1)
      else
         thisGameObject.Renderer.Material.SetColor("_Color",1,0,0,1)
      end
  
end  

thisGameObject.OnUpdate(OnUpdate)

```

### InRange

bool InRange(SVector other, float range)

Returns if other is within range meters of this vector, inclusive

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| other | SVector | –                 |
| range | float   | –                 |

القيم المرجعة

`bool`

مثال

**Lua**

```lua
local vector = Vector.New(370, 30, 0);
local vectorOther = Vector.New(372, 30, 0);
Space.Log(vector.InRange(vectorOther, 2.0));
-- prints True

local vector2 = Vector.New(80, 30, 20);
local vectorOther2 = Vector.New(1, 15, 25);
Space.Log(vector2.InRange(vectorOther2, 1.0));
-- prints False

```

**Lua**

```lua
--the below script will change the objects color to green if you are near the object 
--and change color to red if you are far from the object 
--(example: motion sensor lights)

thisGameObject = Space.Host.ExecutingObject

function OnUpdate()
  positionAvatar = Space.Scene.PlayerAvatar.GameObject.WorldPosition
  positionObject = thisGameObject.WorldPosition
  
     if positionAvatar.InRange(positionObject, 5.0) then
         thisGameObject.Renderer.Material.SetColor("_Color",0,1,0,1)
      else
         thisGameObject.Renderer.Material.SetColor("_Color",1,0,0,1)
      end
  
end  

thisGameObject.SubscribeToEvents()
thisGameObject.OnUpdate(OnUpdate)

```

### Cross

SVector Cross(SVector other)

Returns the cross product of this vector and other

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| other | SVector | –                 |

القيم المرجعة

`SVector`

مثال

**Lua**

```lua
local vector = Vector.New(0, 1, 0);
local vectorOther = Vector.New(1, 0, 0);
Space.Log(vector.Cross(vectorOther));
-- prints [0, 0, -1]

```

### Lerp

SVector Lerp(SVector other, float t)

Linear interpolates between this and other based on factor t (0-1)

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| other | SVector | –                 |
| t     | float   | –                 |

القيم المرجعة

`SVector`

مثال

**Lua**

```lua
lerpVector = currentVector.Lerp(targetVector, 0.5)

```

**Lua**

```lua
-- Lua Translation of Unity C# Documentation

--[["StartMarker" and "EndMaker" are game objects set up as endpoints.
These objects are attached to the script in the Object Reference section.
The name fields in that section should match these names for the example. --]]
local startMarker = Space.Host.GetReference("StartMarker");
local endMarker = Space.Host.GetReference("EndMarker");
local ball = Space.Host.ExecutingObject;
local speed = 1.0;
local startTime;
local journeyLength;
ball.SubscribeToEvents();

local onStartMethod = function()
  startTime = Space.Time;
  journeyLength = startMarker.LocalPosition.Distance(endMarker.LocalPosition);
end

-- This ball object will move from the start endpoint object to the end endpoint.
local moveBall = function()
  local distCovered = (Space.Time - startTime) * speed;
  local fracJourney = distCovered / journeyLength;
  ball.LocalPosition = startMarker.LocalPosition.Lerp(endMarker.LocalPosition, fracJourney);
end

ball.OnStart(onStartMethod);
ball.OnUpdate(moveBall);

```

### Slerp

SVector Slerp(SVector other, float t)

Spherically linear interpolates between this and other based on factor t (0-1)

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| other | SVector | –                 |
| t     | float   | –                 |

القيم المرجعة

`SVector`

مثال

**Lua**

```lua
slerpVector = currentVector.Slerp(targetVector, 0.5)

```

**Lua**

```lua
-- Lua Translation of Unity C# Documentation

--[["Sunrise" and "Sunset" are game objects set up as endpoints.
These objects are attached to the script in the Object Reference section.
The name fields in that section should match these names for the example. --]]
local sunrise = Space.Host.GetReference("Sunrise");
local sunset = Space.Host.GetReference("Sunset");

local ball = Space.Host.ExecutingObject;
local startTime;
local journeyTime = 1.0;
ball.SubscribeToEvents();

local onStartMethod = function()
  startTime = Space.Time;
end

-- This ball object will move from the start endpoint object to the end endpoint.
local moveBall = function()
  local center = (sunrise.LocalPosition + sunset.LocalPosition) * 0.5;
  center = center - Vector.Up;
  local riseRelCenter = sunrise.LocalPosition - center;
  local setRelCenter = sunset.LocalPosition - center;
  local fracComplete = (Space.Time - startTime) / journeyTime;

  ball.LocalPosition = riseRelCenter.Slerp(setRelCenter, fracComplete);
  ball.LocalPosition = ball.LocalPosition + center;
end

ball.OnStart(onStartMethod);
ball.OnUpdate(moveBall);

```

### MoveTowards

SVector MoveTowards(SVector other, float maxDistance)

Moves this vector closer to other by a maximum of maxDistance units

المعاملات

| الاسم       | النوع   | القيمة الافتراضية |
| ----------- | ------- | ----------------- |
| other       | SVector | –                 |
| maxDistance | float   | –                 |

القيم المرجعة

`SVector`

مثال

**Lua**

```lua
newVector = currentVector.MoveTowards(targetVector)

```

**Lua**

```lua
-- Lua Translation of Unity C# Documentation

--[["Target" is a game object set up as a target position.
This object is attached to the script in the Object Reference section.
The name field in that section should match this name for the example. --]]
local target = Space.Host.GetReference("Target");

local ball = Space.Host.ExecutingObject;
local speed = 1.0;Vecto

local onStartMethod = function()
  startTime = Space.Time;
end

-- This ball object will move towards the target. Negative values for
-- the maxDistance parameter will push the ball away from the target.
local moveBall = function()
  local step = speed * Space.DeltaTime;
  ball.LocalPosition = ball.LocalPosition.MoveTowards(target.LocalPosition, step);
end

ball.OnStart(onStartMethod);
ball.OnUpdate(moveBall);

-- NOTE: If you use MoveTowards, the movement will not overshoot the target.

```

### Dot

float Dot(SVector other)

Returns the dot product between this and other (note - normalise your vectors first!

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| other | SVector | –                 |

القيم المرجعة

`float`

مثال

**Lua**

```lua
local vectorA = Vector.New(0, 1, 0);
local vectorOtherA = Vector.New(1, 0, 0);
Space.Log(vectorA.Dot(vectorOtherA));
-- prints 0

local vectorB = Vector.New(0, 1, 0);
local vectorOtherB = Vector.New(0, 1, 0);
Space.Log(vectorB.Dot(vectorOtherB));
-- prints 1

local vectorC = Vector.New(0, 1, 0);
local vectorOtherC = Vector.New(0, -1, 0);
Space.Log(vectorC.Dot(vectorOtherC));
-- prints -1

```

### Equals

bool Equals(SVector other)

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| other | SVector | –                 |

القيم المرجعة

`bool`

مثال

**Lua**

```lua
isEqual = Vector.Up.Equals( Vector.New(0,1,0) )

```

### ToString

string ToString()

القيم المرجعة

`string`

مثال

**Lua**

```lua
stringVector = Vector.New(0,0,0).ToString()

```

### New

static SVector New(float x, float y, float z)

Initialises vector from three floats

المعاملات

| الاسم | النوع | القيمة الافتراضية |
| ----- | ----- | ----------------- |
| x     | float | –                 |
| y     | float | –                 |
| z     | float | –                 |

القيم المرجعة

`SVector`

مثال

**Lua**

```lua
newVector = Vector.New(0, 1, 0)

```

### operator+

static SVector operator+(SVector a, SVector b)

static SVector operator+(SVector a, float b)

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| a     | SVector | –                 |
| b     | SVector | –                 |
| b     | float   | –                 |

القيم المرجعة

`SVector`

مثال

**Lua**

```lua
example 1

```

### operator-

static SVector operator-(SVector a, SVector b)

static SVector operator-(SVector a, float b)

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| a     | SVector | –                 |
| b     | SVector | –                 |
| b     | float   | –                 |

القيم المرجعة

`SVector`

مثال

**Lua**

```lua
example 1

```

### operator\*

static SVector operator\*(SVector a, SVector b)

static SVector operator\*(SVector a, float b)

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| a     | SVector | –                 |
| b     | SVector | –                 |
| b     | float   | –                 |

القيم المرجعة

`SVector`

مثال

**Lua**

```lua
example 1

```

### operator/

static SVector operator/(SVector a, SVector b)

static SVector operator/(SVector a, float b)

المعاملات

| الاسم | النوع   | القيمة الافتراضية |
| ----- | ------- | ----------------- |
| a     | SVector | –                 |
| b     | SVector | –                 |
| b     | float   | –                 |

القيم المرجعة

`SVector`

مثال

**Lua**

```lua
example 1

```

## الخصائص

### X

float X {get; set; }

X axis (red axis)

مثال

**Lua**

```lua
newVect = Vector.New(0,0,0)
newVect.X = 5.0

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;
local originalPos = obj.LocalPosition;
obj.SubscribeToEvents();

local onStartMethod = function()
  Space.Log(originalPos.x);
  -- prints the X axis position of this object as a float

  originalPos.x = 100.0;
  -- assigns 100.0 value to the X axis position of this object

  obj.LocalPosition = originalPos;
  -- sets the the new position
end

obj.OnStart(onStartMethod);

```

### Y

float Y {get; set; }

Y axis (green axis)

مثال

**Lua**

```lua
newVect = Vector.New(0,0,0)
newVect.Y = 5.0

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;
local originalPos = obj.LocalPosition;
obj.SubscribeToEvents();

local onStartMethod = function()
  Space.Log(originalPos.y);
  -- prints the Y axis position of this object as a float

  originalPos.y = 100.0;
  -- assigns 100.0 value to the Y axis position of this object

  obj.LocalPosition = originalPos;
  -- sets the the new position
end

obj.OnStart(onStartMethod);

```

### Z

float Z {get; set; }

Z axis (blue axis)

مثال

**Lua**

```lua
newVect = Vector.New(0,0,0)
newVect.Z = 5.0

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject
local originalPos = obj.LocalPosition

local onStartMethod = function()
  Space.Log(originalPos.z)
  -- prints the Z axis position of this object as a float

  originalPos.z = 100.0
  -- assigns 100.0 value to the Z axis position of this object

  obj.LocalPosition = originalPos
  -- sets the the new position
end

obj.OnStart(onStartMethod)

```

### Magnitude

float Magnitude {get; }

Returns the magnitude of this vector

مثال

**Lua**

```lua
vector = Vector.New(1.0, 5.0, 0.0)
vectorMagnitude = vector.Magnitude

```

### Normalised

SVector Normalised {get; }

Returns the normalised version of this vector

مثال

**Lua**

```lua
vector = Vector.New(0.0, 10.0, 0.0)
vectorNormalised = vector.Normalised

```

### Up

static SVector Up {get; }

Equivalent of new SVector(0,1,0)

مثال

**Lua**

```lua
up = Vector.Up

```

**Lua**

```lua
--this script will make clicking this object move 2 units up on the world Y axis
thisObject = Space.Host.ExecutingObject

OnClick = function()
  
  thisObject.WorldPosition = thisObject.WorldPosition + (Vector.Up * 2)
  
end


thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)

```

### Down

static SVector Down {get; }

Equivalent of new SVector(0,-1,0)

مثال

**Lua**

```lua
down = Vector.Down

```

**Lua**

```lua
--this script will make clicking this object move 2 units down on the world Y axis
thisObject = Space.Host.ExecutingObject

OnClick = function()
  
  thisObject.WorldPosition = thisObject.WorldPosition + (Vector.Down * 2)
  
end


thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)

```

### Left

static SVector Left {get; }

Equivalent of new SVector(-1,0,0)

مثال

**Lua**

```lua
left = Vector.Left

```

**Lua**

```lua
--this script will make clicking this object move 2 units left on the world X axis
thisObject = Space.Host.ExecutingObject

OnClick = function()
  
  thisObject.WorldPosition = thisObject.WorldPosition + (Vector.Left * 2)
  
end


thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)

```

### Right

static SVector Right {get; }

Equivalent of new SVector(1,0,0)

مثال

**Lua**

```lua
right = Vector.Right

```

**Lua**

```lua
--this script will make clicking this object move 2 units right on the world X axis
thisObject = Space.Host.ExecutingObject

OnClick = function()
  
  thisObject.WorldPosition = thisObject.WorldPosition + (Vector.Right * 2)
  
end


thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)

```

### Forward

static SVector Forward {get; }

Equivalent of new SVector(0,0,1)

مثال

**Lua**

```lua
forward = Vector.Forward

```

**Lua**

```lua
--this script will make clicking this object move 2 units Forward on the world Z axis
thisObject = Space.Host.ExecutingObject

OnClick = function()
  
  thisObject.WorldPosition = thisObject.WorldPosition + (Vector.Forward * 2)
  
end


thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)

```

### Back

static SVector Back {get; }

Equivalent of new SVector(0,0,-1)

مثال

**Lua**

```lua
back = Vector.Back

```

**Lua**

```lua
--this script will make clicking this object move 2 units Back on the world Z axis
thisObject = Space.Host.ExecutingObject

OnClick = function()
  
  thisObject.WorldPosition = thisObject.WorldPosition + (Vector.Back * 2)
  
end


thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)

```

### Zero

static SVector Zero {get; }

Equivalent of new SVector(0,0,0)

مثال

**Lua**

```lua
vectorZero  = Vector.Zero

```

**Lua**

```lua
--clicking this object move it to the center of the region <0,0,0>
thisObject = Space.Host.ExecutingObject

OnClick = function()

  thisObject.WorldPosition = Vector.Zero

end


thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)

```

### One

static SVector One {get; }

Equivalent of new SVector(1,1,1)

مثال

**Lua**

```lua
vectorOne = Vector.One

```

**Lua**

```lua
--clicking this object move it to the <1,1,1> coordinates of the region.
thisObject = Space.Host.ExecutingObject

OnClick = function()

  thisObject.WorldPosition = Vector.One

end


thisObject.AddClickable()
thisObject.Clickable.OnClick(OnClick)

```

### MaxValue

static SVector MaxValue {get; }

Contains the largest possible vector \[3.402823E+38, 3.402823E+38, 3.402823E+38]

مثال

**Lua**

```lua
vectorMaxValue = Vector.MaxValue

```

### MinValue

static SVector MinValue {get; }

Contains the largest possible negative vector

مثال

**Lua**

```lua
vectorMinValue = Vector.MinValue

```
