# SRigidbody

**Members** 32

|          |                                                       |                                                                                                                         |
| -------- | ----------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| Function | [AddExplosionForce](#addexplosionforce)               | Applies a force to a rigidbody that simulates explosion effects.                                                        |
| Function | [AddForce](#addforce)                                 | Adds a force to the Rigidbody that is continuously exerted on it in the given direction.                                |
| Function | [AddForceAtPosition](#addforceatposition)             | Adds a force to the Rigidbody at a given position (should be within the range of the rigidbody for a realistic result). |
| Function | [AddRelativeTorque](#addrelativetorque)               | Adds a torque to the rigidbody relative to the local coordinate system.                                                 |
| Function | [AddTorque](#addtorque)                               | Adds a torque to the rigidbody relative to the global coordinate system.                                                |
| Function | [ClosestPointOnBounds](#closestpointonbounds)         | Returns the closest point on the bounding box of the attached colliders.                                                |
| Function | [GetPointVelocity](#getpointvelocity)                 | –                                                                                                                       |
| Function | [GetRelativePointVelocity](#getrelativepointvelocity) | –                                                                                                                       |
| Function | [MovePosition](#moveposition)                         | Moves the rigidbody to position.                                                                                        |
| Function | [MoveRotation](#moverotation)                         | Rotates the rigidbody to rotation.                                                                                      |
| Function | [ResetCenterOfMass](#resetcenterofmass)               | Reset the center of mass of the rigidbody.                                                                              |
| Function | [ResetIntertiaTensor](#resetintertiatensor)           | Reset the inertia tensor value and rotation.                                                                            |
| Function | [Sleep](#sleep)                                       | Forces a rigidbody to sleep.                                                                                            |
| Function | [WakeUp](#wakeup)                                     | Forces a rigidbody to wake up.                                                                                          |
| Function | [SweepTestAll](#sweeptestall)                         | Like Rigidbody.SweepTest, but returns all hits.                                                                         |
| Property | [AngularDrag](#angulardrag)                           | The angular drag of the object.                                                                                         |
| Property | [AngularVelocity](#angularvelocity)                   | The angular velocity vector of the rigidbody (in radians per second).                                                   |
| Property | [CenterOfMass](#centerofmass)                         | The center of mass relative to the local origin.                                                                        |
| Property | [Drag](#drag)                                         | The drag of the object.                                                                                                 |
| Property | [FreezeRotation](#freezerotation)                     | Controls whether physics will have any impact on the rotation of the object.                                            |
| Property | [Kinematic](#kinematic)                               | Controls whether physics will have any impact on the object.                                                            |
| Property | [Mass](#mass)                                         | The mass of the rigidbody.                                                                                              |
| Property | [MaxAngularVelocity](#maxangularvelocity)             | The maximum angular velocity of the rigidbody (7 by default).                                                           |
| Property | [MaxDepenetrationVelocity](#maxdepenetrationvelocity) | The maximum depenetration velocity of the rigidbody (1.00000003318135E+32 by default).                                  |
| Property | [UseGravity](#usegravity)                             | Controls whether gravity affects the rigidbody.                                                                         |
| Property | [Velocity](#velocity)                                 | The velocity vector of the rigidbody. (in units per second).                                                            |
| Property | [WorldCenterOfMass](#worldcenterofmass)               | The center of mass of the rigidbody relative to the global origin (Read Only).                                          |
| Property | [Sleeping](#sleeping)                                 | Is the rigidbody sleeping?                                                                                              |
| Property | [Density](#density)                                   | The density of the object (1 by default).                                                                               |
| Property | [InertiaTensor](#inertiatensor)                       | The diagonal inertia tensor of mass relative to the center of mass.                                                     |
| Property | [InertiaTensorRotation](#inertiatensorrotation)       | The rotation of the inertia tensor.                                                                                     |
| Property | [GameObject](#gameobject)                             | –                                                                                                                       |

## Functions

### AddExplosionForce

void AddExplosionForce(float explosionForce, [SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) explosionPosition, float explosionRadius, float upwardsModifier)

Applies a force to a rigidbody that simulates explosion effects. Other rigidbodies will be affected by the explosion within its radius - the closer they are to the explosionPosition, the stronger the force will be exerted on them.

Parameters

| Name              | Type                                                                       | Default |
| ----------------- | -------------------------------------------------------------------------- | ------- |
| explosionForce    | float                                                                      | –       |
| explosionPosition | [SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) | –       |
| explosionRadius   | float                                                                      | –       |
| upwardsModifier   | float                                                                      | –       |

Returns

`void`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.AddExplosionForce (300, Vector.New(0,0,0), 10, 20)

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;

obj.Rigidbody.AddExplosionForce (300, obj.WorldPosition, 10, 20)
-- The explosion will occur at the location of the ExecutingObject.
-- Place other rigidbodies around it to observe the effect!

```

### AddForce

void AddForce([SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) force)

Adds a force to the Rigidbody that is continuously exerted on it in the given direction.

Parameters

| Name  | Type                                                                       | Default |
| ----- | -------------------------------------------------------------------------- | ------- |
| force | [SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) | –       |

Returns

`void`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.AddForce(Vector.New(0,1,0))

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;

obj.Rigidbody.AddForce (Vector.New(0,100,0));
-- Now the rigidbody is under a continuous force directed upwards (Y direction)

```

### AddForceAtPosition

void AddForceAtPosition([SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) force, [SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) position)

Adds a force to the Rigidbody at a given position (should be within the range of the rigidbody for a realistic result). Thus, both a torque and force are applied to the object.

Parameters

| Name     | Type                                                                       | Default |
| -------- | -------------------------------------------------------------------------- | ------- |
| force    | [SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) | –       |
| position | [SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) | –       |

Returns

`void`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.AddForceAtPosition(Vector.New(1,1,1), Vector.New(0,1,0))

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;
local applyForceHere = Vector.New(obj.WorldPosition.x-0.5,obj.WorldPosition.y-0.5,obj.WorldPosition.z-0.5)
-- This vector is equivalent to one of the lower corners of a 1x1x1 cube.

obj.Rigidbody.AddForceAtPosition (Vector.New(0,40,0), applyForceHere);
-- The object is experiencing an effect similar to being tipped upwards at the aforementioned corner.

```

### AddRelativeTorque

void AddRelativeTorque([SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) torque)

Adds a torque to the rigidbody relative to the local coordinate system.

Parameters

| Name   | Type                                                                       | Default |
| ------ | -------------------------------------------------------------------------- | ------- |
| torque | [SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) | –       |

Returns

`void`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.AddRelativeTorque(Vector.New(0,1,0))

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;

obj.Rigidbody.AddRelativeTorque (Vector.New(0,100,0));
-- Now the object spins about its own Y axis

```

### AddTorque

void AddTorque([SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) torque)

Adds a torque to the rigidbody relative to the global coordinate system.

Parameters

| Name   | Type                                                                       | Default |
| ------ | -------------------------------------------------------------------------- | ------- |
| torque | [SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) | –       |

Returns

`void`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.AddTorque(Vector.New(0,1,0))

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;

obj.Rigidbody.AddTorque (Vector.New(0,100,0));
-- Now the object spins about the global Y axis

```

### ClosestPointOnBounds

[SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) ClosestPointOnBounds([SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) input)

Returns the closest point on the bounding box of the attached colliders.

Parameters

| Name  | Type                                                                       | Default |
| ----- | -------------------------------------------------------------------------- | ------- |
| input | [SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) | –       |

Returns

`SVector`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.ClosestPointOnBounds(Vector.New(1,1,1))

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;

Space.Log(obj.Rigidbody.ClosestPointOnBounds (Vector.Zero));
-- prints [x,y,z] to the console, where x,y,z are coordinates of the rigidbody's point that is the closest to the global origin

```

### GetPointVelocity

[SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) GetPointVelocity([SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) worldPoint)

Parameters

| Name       | Type                                                                       | Default |
| ---------- | -------------------------------------------------------------------------- | ------- |
| worldPoint | [SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) | –       |

Returns

`SVector`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.GetPointVelocity(Vector.New(0,1,0))

```

### GetRelativePointVelocity

[SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) GetRelativePointVelocity([SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) point)

Parameters

| Name  | Type                                                                       | Default |
| ----- | -------------------------------------------------------------------------- | ------- |
| point | [SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) | –       |

Returns

`SVector`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.GetRelativePointVelocity(Vector.New(1,1,1))

```

### MovePosition

void MovePosition([SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) point)

Moves the rigidbody to position.

Parameters

| Name  | Type                                                                       | Default |
| ----- | -------------------------------------------------------------------------- | ------- |
| point | [SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) | –       |

Returns

`void`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.MovePosition(Vector.New(1,1,1))

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;
local moveHere = Vector.New(obj.WorldPosition.x+10,obj.WorldPosition.y,obj.WorldPosition.z);

obj.Rigidbody.MovePosition (moveHere);
-- The object has been moved by 10 units in the positive X direction

```

### MoveRotation

void MoveRotation([SQuaternion](/docs/scripting/client-scripting-api-reference/types/squaternion.md) rotation)

Rotates the rigidbody to rotation.

Parameters

| Name     | Type                                                                               | Default |
| -------- | ---------------------------------------------------------------------------------- | ------- |
| rotation | [SQuaternion](/docs/scripting/client-scripting-api-reference/types/squaternion.md) | –       |

Returns

`void`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.MoveRotation(Quaternion.New(0,1,0,0))

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;
local setRotationTo = Quaternion.Euler(60,0,0)

obj.Rigidbody.MoveRotation (setRotationTo);
-- The object's rotation has been set to 60 degrees in the positive X direction and 0 in Y and Z

```

### ResetCenterOfMass

void ResetCenterOfMass()

Reset the center of mass of the rigidbody.

Returns

`void`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.ResetCenterOfMass()

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;

obj.Rigidbody.CenterOfMass = Vector.New(1,1,1);
Space.Log(obj.Rigidbody.CenterOfMass);
-- prints "[1,1,1]" to the console

obj.Rigidbody.ResetCenterOfMass();
Space.Log(obj.Rigidbody.CenterOfMass);
-- prints "[0,0,0]" to the console

```

### ResetIntertiaTensor

void ResetIntertiaTensor()

Reset the inertia tensor value and rotation.

Returns

`void`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.ResetIntertiaTensor()

```

**Lua**

```lua
solid = Space.Scene.Find("Solid")
--get rigidbody of inertia frame.
rigid = solid.Rigidbody
if rigid == nil then
    rigid = solid.AddRigidbody()
end
rigid.ResetIntertiaTensor()
--to reset inertia tensor if intertia tensor is set

```

### Sleep

void Sleep()

Forces a rigidbody to sleep.

Returns

`void`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.Sleep()

```

### WakeUp

void WakeUp()

Forces a rigidbody to wake up.

Returns

`void`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.WakeUp()

```

### SweepTestAll

[SPhysicsHit](/docs/scripting/client-scripting-api-reference/types/sphysicshit.md)\[] SweepTestAll([SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) direction, float distance)

Like Rigidbody.SweepTest, but returns all hits.

Parameters

| Name      | Type                                                                       | Default |
| --------- | -------------------------------------------------------------------------- | ------- |
| direction | [SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) | –       |
| distance  | float                                                                      | –       |

Returns

`SPhysicsHit[]`

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.SweepTestAll(Vector.New(1,0,0) , 20)

```

**Lua**

```lua
solid = Space.Scene.Find("Solid")
--get rigidbody of inertia frame.
rigid = solid.Rigidbody
if rigid == nil then
    rigid = solid.AddRigidbody()
end
hits = rigid.SweepTestAll(solid.Forward , 20)
--sweep forward 20 meters, and return all hits.
if hits~=nil and #hits-1 > 0 then
    for i = 1,#hits-1 do
        Space.Log(hits[i].Object.Name)
    end
end
--output all hit gameobject.

```

## Properties

### AngularDrag

float AngularDrag {get; set; }

The angular drag of the object.

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.AngularDrag = 0.20

```

### AngularVelocity

[SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) AngularVelocity {get; set; }

The angular velocity vector of the rigidbody (in radians per second).

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.AngularVelocity = Vector.New(0,1,0)

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;

-- Set a new angular velocity vector
obj.Rigidbody.AngularVelocity = Vector.New(0,Space.Math.Pi,0);
-- Now the object is rotating about the Y axis at a speed of 180 degrees per second
-- (or 30 revolutions per minute)

-- Get the current angular velocity vector
Space.Log(obj.Rigidbody.AngularVelocity);
-- prints "[0, 3.141593, 0]" to the console

```

### CenterOfMass

[SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) CenterOfMass {get; set; }

The center of mass relative to the local origin.

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.CenterOfMass = Vector.New(1,0,0)

```

### Drag

float Drag {get; set; }

The drag of the object.

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.Drag = 5

```

### FreezeRotation

bool FreezeRotation {get; set; }

Controls whether physics will have any impact on the rotation of the object.

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.FreezeRotation = true

```

### Kinematic

bool Kinematic {get; set; }

Controls whether physics will have any impact on the object.

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.Kinematic = true

```

### Mass

float Mass {get; set; }

The mass of the rigidbody.

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.Mass = 0.1

```

### MaxAngularVelocity

float MaxAngularVelocity {get; set; }

The maximum angular velocity of the rigidbody (7 by default). Can be useful to prevent an object from spinning uncontrollably fast.

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.MaxAngularVelocity = 1

```

### MaxDepenetrationVelocity

float MaxDepenetrationVelocity {get; set; }

The maximum depenetration velocity of the rigidbody (1.00000003318135E+32 by default). Can be useful to make colliding objects bounce away in a smoother fashion.

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.MaxDepenetrationVelocity = 1

```

### UseGravity

bool UseGravity {get; set; }

Controls whether gravity affects the rigidbody.

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.UseGravity = true

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;

-- Set UseGravity to False (it is set to True by default)
obj.Rigidbody.UseGravity = false;
-- Now gravity does not affect the rigidbody.

-- Get the UseGravity value (find out if UseGravity is in action)
Space.Log(obj.Rigidbody.UseGravity);
-- prints "False" to the console

```

### Velocity

[SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) Velocity {get; set; }

The velocity vector of the rigidbody. (in units per second).

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.Velocity = Vector.New(0,1,0)

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;

-- Set a new velocity vector
obj.Rigidbody.Velocity = Vector.New(0, 0, 1);
-- Now the object is moving in the positive Z direction at a speed of 1 unit per second

-- Get the current velocity vector
Space.Log(obj.Rigidbody.Velocity);
-- prints "[0, 0, 1]" to the console

```

### WorldCenterOfMass

[SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) WorldCenterOfMass {get; }

The center of mass of the rigidbody relative to the global origin (Read Only).

Example

\`\`\` WorldCenter = Space.Host.ExecutingObject.Rigidbody.WorldCenterOfMass \`\`\`

**Lua**

```lua
local obj = Space.Host.ExecutingObject;

-- Get the current center of mass
Space.Log(obj.Rigidbody.WorldCenterOfMass);
-- prints "[x, y, z]" to the console, where x,y,z are global coordinates of the center of mass. If CenterOfMass == [0,0,0], then x,y,z are equal to the global coordinates of the object.

```

### Sleeping

bool Sleeping {get; }

Is the rigidbody sleeping?

Example

**Lua**

```lua
isSleeping = Space.Host.ExecutingObject.Rigidbody.Sleeping

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;

obj.Rigidbody.Sleep();
Space.Log(obj.Rigidbody.Sleeping);
-- prints "True" to the console

obj.Rigidbody.WakeUp();
Space.Log(obj.Rigidbody.Sleeping);
-- prints "False" to the console

```

### Density

float Density {set; }

The density of the object (1 by default). Changing this value will affect the mass of the object (the volume will remain unchanged).

Example

**Lua**

```lua
density = Space.Host.ExecutingObject.Rigidbody.Density

```

**Lua**

```lua
local obj = Space.Host.ExecutingObject;

Space.Log(obj.Rigidbody.Mass);
-- prints "1" to the console
obj.LocalScale = Vector.New(2,2,2);
obj.Rigidbody.Density = 0.5;
Space.Log(obj.Rigidbody.Mass);
-- prints "4" to the console - the density is 2 times lower, and the object is 8 times bigger, therefore it's 4 times heavier.

```

### InertiaTensor

[SVector](/docs/scripting/client-scripting-api-reference/types/svector.md) InertiaTensor {get; set; }

The diagonal inertia tensor of mass relative to the center of mass. It is defined in x,y,z axis. It is calculate by physics automatically,and if you set value to it, it would override the value.

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.IntertiaTensor = Vector.New(0,0,0)

```

**Lua**

```lua
solid = Space.Scene.Find("Solid")
--get rigidbody of inertia frame.
rigid = solid.Rigidbody
if rigid == nil then
    rigid = solid.AddRigidbody()
end
rigid.InertiaTensor = Vector.New(10,100,1)
rigid.AddTorque(Vector.New(100,100,100))
--set inertia tensor to 10,100,1, and add torque 100 to all axis,and rotate velocity x:y:z would be 10:1:100.

```

### InertiaTensorRotation

[SQuaternion](/docs/scripting/client-scripting-api-reference/types/squaternion.md) InertiaTensorRotation {get; set; }

The rotation of the inertia tensor.

Example

**Lua**

```lua
Space.Host.ExecutingObject.Rigidbody.InertiaTensorRotation = Quaternion.New(0,0,0,0)

```

**Lua**

```lua
solid = Space.Scene.Find("Solid")
--get rigidbody of inertia frame.
rigid = solid.Rigidbody
if rigid == nil then
    rigid = solid.AddRigidbody()
end
rigid.InertiaTensor = Vector.New(10,100,1)
rigid.InertiaTensorRotation = Quaternion.Euler(0,90,0)
rigid.AddTorque(Vector.New(100,100,100))
--set inertia tensor manually and rotate this inertia tensor by 90 degrees in y axis.

```

### GameObject

[SGameObject](/docs/scripting/client-scripting-api-reference/types/sgameobject.md) GameObject {get; }

Example

**Lua**

```lua
theGameObject = Space.Host.ExecutingObject.Rigidbody.GameObject

```
