Sinespace Client  2023.2.17543
Client-side scripting for Sinespace
SineSpace.Scripting.Components.SRigidbody Class Reference
Inheritance diagram for SineSpace.Scripting.Components.SRigidbody:
ScriptClassComponent< Rigidbody >

Public Member Functions

void AddExplosionForce (float explosionForce, SVector explosionPosition, float explosionRadius, float upwardsModifier)
 Applies a force to a rigidbody that simulates explosion effects. Other rigid bodies 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. More...
 
void AddForce (SVector force)
 Adds a force to the Rigidbody that is continuously exerted on it in the given direction. More...
 
void AddForceAtPosition (SVector force, SVector 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. More...
 
void AddRelativeTorque (SVector torque)
 Adds a torque to the rigidbody relative to the local coordinate system. More...
 
void AddTorque (SVector torque)
 Adds a torque to the rigidbody relative to the global coordinate system. More...
 
SVector ClosestPointOnBounds (SVector input)
 Returns the closest point on the bounding box of the attached colliders. More...
 
SVector GetPointVelocity (SVector worldPoint)
 The velocity of the rigidbody at the point worldPoint in global space. More...
 
SVector GetRelativePointVelocity (SVector point)
 The velocity relative to the rigidbody at the point relativePoint. More...
 
void MovePosition (SVector point)
 Moves the rigidbody to position. More...
 
void MoveRotation (SQuaternion rotation)
 Rotates the rigidbody to rotation. More...
 
void ResetCenterOfMass ()
 Reset the center of mass of the rigidbody. More...
 
void ResetInertiaTensor ()
 Reset the inertia tensor value and rotation. More...
 
void Sleep ()
 Forces a rigidbody to sleep. More...
 
void WakeUp ()
 Forces a rigidbody to wake up. More...
 
SPhysicsHit[] SweepTestAll (SVector direction, float distance)
 Like Rigidbody.SweepTest, but returns all hits. More...
 

Properties

float AngularDrag [get, set]
 The angular drag of the object. More...
 
SVector AngularVelocity [get, set]
 The angular velocity vector of the rigidbody (in radians per second). More...
 
SVector CenterOfMass [get, set]
 The center of mass relative to the local origin. More...
 
float Drag [get, set]
 The drag of the object. More...
 
bool FreezeRotation [get, set]
 Controls whether physics will have any impact on the rotation of the object. More...
 
bool Kinematic [get, set]
 Controls whether physics will have any impact on the object. More...
 
float Mass [get, set]
 The mass of the rigidbody. More...
 
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. More...
 
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. More...
 
bool UseGravity [get, set]
 Controls whether gravity affects the rigidbody. More...
 
SVector Velocity [get, set]
 The velocity vector of the rigidbody. (in units per second). More...
 
SVector WorldCenterOfMass [get]
 The center of mass of the rigidbody relative to the global origin (Read Only). More...
 
bool Sleeping [get]
 Is the rigidbody sleeping? More...
 
float Density [set]
 The density of the object (1 by default). Changing this value will affect the mass of t he object (the volume will remain unchanged). More...
 
SVector 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. More...
 
SQuaternion InertiaTensorRotation [get, set]
 The rotation of the inertia tensor. More...
 
- Properties inherited from ScriptClassComponent< Rigidbody >
SGameObject GameObject [get]
 Return the GameObject which component added. More...
 

Member Function Documentation

◆ AddExplosionForce()

void SineSpace.Scripting.Components.SRigidbody.AddExplosionForce ( float  explosionForce,
SVector  explosionPosition,
float  explosionRadius,
float  upwardsModifier 
)

Applies a force to a rigidbody that simulates explosion effects. Other rigid bodies 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.

local obj = Space.Host.ExecutingObject;
obj.Rigidbody.AddExplosionForce (300, obj.WorldPosition, 10, 20)
&ndash; The explosion will occur at the location of the ExecutingObject.
&ndash; Place other rigid bodies around it to observe the effect!

◆ AddForce()

void SineSpace.Scripting.Components.SRigidbody.AddForce ( SVector  force)

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

local obj = Space.Host.ExecutingObject;
obj.Rigidbody.AddForce (Vector.New(0,100,0));
&ndash; Now the rigidbody is under a continuous force directed upwards
(Y direction)

◆ AddForceAtPosition()

void SineSpace.Scripting.Components.SRigidbody.AddForceAtPosition ( SVector  force,
SVector  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.

local obj = Space.Host.ExecutingObject;
local applyForceHere = Vector.New(obj.WorldPosition.x-0.5,obj.
WorldPosition.y-0.5,obj.WorldPosition.z-0.5)
&ndash; This vector is equivalent to one of the lower corners of a 1x1x1 cube.
obj.Rigidbody.AddForceAtPosition (Vector.New(0,40,0), applyForceHere);
&ndash; The object is experiencing an effect similar to being tipped upwards at the
aforementioned corner.

◆ AddRelativeTorque()

void SineSpace.Scripting.Components.SRigidbody.AddRelativeTorque ( SVector  torque)

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

local obj = Space.Host.ExecutingObject;
obj.Rigidbody.AddRelativeTorque (Vector.New(0,100,0));
&ndash; Now the object spins about its own Y axis

◆ AddTorque()

void SineSpace.Scripting.Components.SRigidbody.AddTorque ( SVector  torque)

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

local obj = Space.Host.ExecutingObject;
obj.Rigidbody.AddTorque (Vector.New(0,100,0));
&ndash; Now the object spins about the global Y axis

◆ ClosestPointOnBounds()

SVector SineSpace.Scripting.Components.SRigidbody.ClosestPointOnBounds ( SVector  input)

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

local obj = Space.Host.ExecutingObject;
Space.Log(obj.Rigidbody.ClosestPointOnBounds (Vector.Zero));
&ndash; 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 SineSpace.Scripting.Components.SRigidbody.GetPointVelocity ( SVector  worldPoint)

The velocity of the rigidbody at the point worldPoint in global space.

&ndash;get rigidbody of inertia frame
solid = Space.Scene.Find("Solid")
rigid = solid.Rigidbody
if rigid == nil then
rigid = solid.AddRigidbody()
end
&ndash;Add torque to rigidbody and output point velocity
rigid.AddTorque(Vector.New(100,0,0))
Space.Log(rigid.GetPointVelocity(Vector.New(0.5,0.5,0.5)).ToString())

◆ GetRelativePointVelocity()

SVector SineSpace.Scripting.Components.SRigidbody.GetRelativePointVelocity ( SVector  point)

The velocity relative to the rigidbody at the point relativePoint.

&ndash;get rigidbody of inertia frame
solid = Space.Scene.Find("Solid")
rigid = solid.Rigidbody
if rigid == nil then
rigid = solid.AddRigidbody()
end
&ndash;Add torque to rigidbody and output relative point velocity
rigid.AddTorque(Vector.New(100,0,0))
Space.Log(rigid.GetRelativePointVelocity(Vector.New(1,1,1)).ToString())

◆ MovePosition()

void SineSpace.Scripting.Components.SRigidbody.MovePosition ( SVector  point)

Moves the rigidbody to position.

local obj = Space.Host.ExecutingObject;
local moveHere = Vector.New(obj.WorldPosition.x+10,
obj.WorldPosition.y,obj.WorldPosition.z);
obj.Rigidbody.MovePosition (moveHere);
&ndash; The object has been moved by 10 units in the positive X direction

◆ MoveRotation()

void SineSpace.Scripting.Components.SRigidbody.MoveRotation ( SQuaternion  rotation)

Rotates the rigidbody to rotation.

local obj = Space.Host.ExecutingObject;
local setRotationTo = Quaternion.Euler(60,0,0)
obj.Rigidbody.MoveRotation (setRotationTo);
&ndash; The object's rotation has been set to 60 degrees in the positive X
direction and 0 in Y and Z

◆ ResetCenterOfMass()

void SineSpace.Scripting.Components.SRigidbody.ResetCenterOfMass ( )

Reset the center of mass of the rigidbody.

local obj = Space.Host.ExecutingObject;
obj.Rigidbody.CenterOfMass = Vector.New(1,1,1);
Space.Log(obj.Rigidbody.CenterOfMass);
&ndash; prints "[1,1,1]" to the console
obj.Rigidbody.ResetCenterOfMass();
Space.Log(obj.Rigidbody.CenterOfMass);
&ndash; prints "[0,0,0]" to the console

◆ ResetInertiaTensor()

void SineSpace.Scripting.Components.SRigidbody.ResetInertiaTensor ( )

Reset the inertia tensor value and rotation.

&ndash;get rigidbody of inertia frame
inertia = Space.Scene.Find("InertiaFrame")
rigid = inertia.Rigidbody
if rigid == nil then
rigid = inertia.AddRigidbody()
end
&ndash;to reset inertia tensor if intertia tensor is set
rigid.ResetIntertiaTensor()

◆ Sleep()

void SineSpace.Scripting.Components.SRigidbody.Sleep ( )

Forces a rigidbody to sleep.

local obj = Space.Host.ExecutingObject;
obj.Rigidbody.Sleep();
Space.Log(obj.Rigidbody.Sleeping);
&ndash; prints "True" to the console
obj.Rigidbody.WakeUp();
Space.Log(obj.Rigidbody.Sleeping);
&ndash; prints "False" to the console

◆ SweepTestAll()

SPhysicsHit [] SineSpace.Scripting.Components.SRigidbody.SweepTestAll ( SVector  direction,
float  distance 
)

Like Rigidbody.SweepTest, but returns all hits.

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

◆ WakeUp()

void SineSpace.Scripting.Components.SRigidbody.WakeUp ( )

Forces a rigidbody to wake up.

local obj = Space.Host.ExecutingObject;
obj.Rigidbody.Sleep();
Space.Log(obj.Rigidbody.Sleeping);
&ndash; prints "True" to the console
obj.Rigidbody.WakeUp();
Space.Log(obj.Rigidbody.Sleeping);
&ndash; prints "False" to the console

Property Documentation

◆ AngularDrag

float SineSpace.Scripting.Components.SRigidbody.AngularDrag
getset

The angular drag of the object.

local obj = Space.Host.ExecutingObject;
&ndash; Set a new angular drag value
obj.Rigidbody.AngularDrag = 0.20;
&ndash; Get the current angular drag value
Space.Log(obj.Rigidbody.AngularDrag);
&ndash; prints "0.200000..." to the console

◆ AngularVelocity

SVector SineSpace.Scripting.Components.SRigidbody.AngularVelocity
getset

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

local obj = Space.Host.ExecutingObject;
&ndash; Set a new angular velocity vector
obj.Rigidbody.AngularVelocity = Vector.New(0,Space.Math.Pi,0);
&ndash; Now the object is rotating about the Y axis at a speed of 180 degrees per second
&ndash; (or 30 revolutions per minute)
&ndash; Get the current angular velocity vector
Space.Log(obj.Rigidbody.AngularVelocity);
&ndash; prints "[0, 3.141593, 0]" to the console

◆ CenterOfMass

SVector SineSpace.Scripting.Components.SRigidbody.CenterOfMass
getset

The center of mass relative to the local origin.

local obj = Space.Host.ExecutingObject;
&ndash; Set a new center of mass
obj.Rigidbody.CenterOfMass = Vector.New(1,0,0);
&ndash; Now the object's center of mass has been moved by 1 at the X axis
&ndash; Get the current center of mass
Space.Log(obj.Rigidbody.CenterOfMass);
&ndash; prints "[1, 0, 0]" to the console

◆ Density

float SineSpace.Scripting.Components.SRigidbody.Density
set

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

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

◆ Drag

float SineSpace.Scripting.Components.SRigidbody.Drag
getset

The drag of the object.

local obj = Space.Host.ExecutingObject;
&ndash; Set a new drag value
obj.Rigidbody.Drag = 20;
&ndash; Now the object's drag is set to 20 - the higher the number, the more it is resistant to
&ndash;gravity
&ndash; Get the current drag value
Space.Log(obj.Rigidbody.Drag);
&ndash; prints "20" to the console

◆ FreezeRotation

bool SineSpace.Scripting.Components.SRigidbody.FreezeRotation
getset

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

local obj = Space.Host.ExecutingObject;
&ndash; Set FreezeRotation to True
obj.Rigidbody.FreezeRotation = true;
&ndash; Now under no circumstances the object's rotation coordinates will change.
&ndash; Get the FreezeRotation value (find out if Freeze Rotation is in action)
Space.Log(obj.Rigidbody.FreezeRotation);
&ndash; prints "True" to the console

◆ InertiaTensor

SVector SineSpace.Scripting.Components.SRigidbody.InertiaTensor
getset

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.

&ndash;get rigidbody form game object “solid”
solid = Space.Scene.Find("Solid")
rigid = solid.Rigidbody
if rigid == nil then
rigid = solid.AddRigidbody()
end
&ndash;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
rigid.InertiaTensor = Vector.New(10,100,1)
rigid.AddTorque(Vector.New(100,100,100))

◆ InertiaTensorRotation

SQuaternion SineSpace.Scripting.Components.SRigidbody.InertiaTensorRotation
getset

The rotation of the inertia tensor.

&ndash;get rigidbody form game object “solid”
solid = Space.Scene.Find("Solid")
rigid = solid.Rigidbody
if rigid == nil then
rigid = solid.AddRigidbody()
end
&ndash;set inertia tensor manually and rotate this inertia tensor by 90 degrees in y axis
rigid.InertiaTensor = Vector.New(10,100,1)
rigid.InertiaTensorRotation = Quaternion.Euler(0,90,0)
rigid.AddTorque(Vector.New(100,100,100))

◆ Kinematic

bool SineSpace.Scripting.Components.SRigidbody.Kinematic
getset

Controls whether physics will have any impact on the object.

local obj = Space.Host.ExecutingObject;
&ndash; Set Kinematic to True
obj.Rigidbody.Kinematic = true;
&ndash; Now the object will not be affected by gravity, collisions, or other forces.
&ndash; Get the Kinematic value (find out if Kinematic is in action)
Space.Log(obj.Rigidbody.Kinematic);
&ndash; prints "True" to the console

◆ Mass

float SineSpace.Scripting.Components.SRigidbody.Mass
getset

The mass of the rigidbody.

local obj = Space.Host.ExecutingObject;
&ndash; Set a new mass of the rigidbody
obj.Rigidbody.Mass = 0.1;
&ndash; Get the current value of the rigidbody's mass
Space.Log(obj.Rigidbody.Mass);
&ndash; prints "0.1000000..." to the console

◆ MaxAngularVelocity

float SineSpace.Scripting.Components.SRigidbody.MaxAngularVelocity
getset

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

local obj = Space.Host.ExecutingObject;
&ndash; Set a new value for the maximum angular velocity
obj.Rigidbody.MaxAngularVelocity = 1;
&ndash; Now the object, for example, is more resistant to rolling over upon collision with
another object.
&ndash; Get the current value of the rigidbody's maximum angular velocity
Space.Log(obj.Rigidbody.MaxAngularVelocity);
&ndash; prints "1" to the console

◆ MaxDepenetrationVelocity

float SineSpace.Scripting.Components.SRigidbody.MaxDepenetrationVelocity
getset

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.

local obj = Space.Host.ExecutingObject;
&ndash; Set a new value for the maximum depenetration velocity
obj.Rigidbody.MaxDepenetrationVelocity = 1;
&ndash; Get the current value of the rigidbody's maximum depenetration velocity
Space.Log(obj.Rigidbody.MaxDepenetrationVelocity);
&ndash; prints "1" to the console

◆ Sleeping

bool SineSpace.Scripting.Components.SRigidbody.Sleeping
get

Is the rigidbody sleeping?

local obj = Space.Host.ExecutingObject;
obj.Rigidbody.Sleep();
Space.Log(obj.Rigidbody.Sleeping);
&ndash; prints "True" to the console
obj.Rigidbody.WakeUp();
Space.Log(obj.Rigidbody.Sleeping);
&ndash; prints "False" to the console

◆ UseGravity

bool SineSpace.Scripting.Components.SRigidbody.UseGravity
getset

Controls whether gravity affects the rigidbody.

local obj = Space.Host.ExecutingObject;
&ndash; Set UseGravity to False (it is set to True by default)
obj.Rigidbody.UseGravity = false;
&ndash; Now gravity does not affect the rigidbody.
&ndash; Get the UseGravity value (find out if UseGravity is in action)
Space.Log(obj.Rigidbody.UseGravity);
&ndash; prints "False" to the console

◆ Velocity

SVector SineSpace.Scripting.Components.SRigidbody.Velocity
getset

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

local obj = Space.Host.ExecutingObject;
&ndash; Set a new velocity vector
obj.Rigidbody.Velocity = Vector.New(0, 0, 1);
&ndash; Now the object is moving in the positive Z direction at a speed of 1 unit per second
&ndash; Get the current velocity vector
Space.Log(obj.Rigidbody.Velocity);
&ndash; prints "[0, 0, 1]" to the console

◆ WorldCenterOfMass

SVector SineSpace.Scripting.Components.SRigidbody.WorldCenterOfMass
get

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

local obj = Space.Host.ExecutingObject;
&ndash; Get the current center of mass
Space.Log(obj.Rigidbody.WorldCenterOfMass);
&ndash; 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.
SineSpace.Scripting.Components.SRigidbody.Kinematic
bool Kinematic
Controls whether physics will have any impact on the object.
Definition: SRigidbody.cs:127
SineSpace.Scripting.Components.SRigidbody.UseGravity
bool UseGravity
Controls whether gravity affects the rigidbody.
Definition: SRigidbody.cs:209
SineSpace.Scripting.Components.SRigidbody.FreezeRotation
bool FreezeRotation
Controls whether physics will have any impact on the rotation of the object.
Definition: SRigidbody.cs:107
SineSpace.Scripting.Components.SRigidbody.CenterOfMass
SVector CenterOfMass
The center of mass relative to the local origin.
Definition: SRigidbody.cs:66