wiki.sine.space | sinespace

Difference between revisions of "Scripting/SRigidbody"

From wiki.sine.space
Jump to: navigation, search
(Added 4 more Properties (FreezeRotation, Kinematic, Mass, MaxAngularVelocity) and a Navbox.)
(Added MaxDepenetrationVelocity and UseGravity ; fixed some grammar and an error in one of the scripts submitted earlier.)
Line 78: Line 78:
 
{{ScriptFunction|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.|5=
 
{{ScriptFunction|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.|5=
  
local obj = Space.Host.MaxAngularVelocity;<br><br>
+
local obj = Space.Host.ExecutingObject;<br><br>
''-- Set a new maximum angular velocity''<br>
+
''-- Set a new value for the maximum angular velocity''<br>
 
obj.Rigidbody.MaxAngularVelocity = 1;<br>
 
obj.Rigidbody.MaxAngularVelocity = 1;<br>
 
''-- Now the object, for example, is more resistant to rolling over upon collision with another object.''<br><br>
 
''-- Now the object, for example, is more resistant to rolling over upon collision with another object.''<br><br>
Line 85: Line 85:
 
Space.Log(obj.Rigidbody.MaxAngularVelocity);<br>
 
Space.Log(obj.Rigidbody.MaxAngularVelocity);<br>
 
''-- prints "1" to the console''}}
 
''-- prints "1" to the console''}}
 +
 +
 +
{{ScriptFunction|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.|5=
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- Set a new value for the maximum depenetration velocity''<br>
 +
obj.Rigidbody.MaxDepenetrationVelocity = 1;<br><br>
 +
''-- Get the current value of the rigidbody's maximum depenetration velocity''<br>
 +
Space.Log(obj.Rigidbody.MaxDepenetrationVelocity);<br>
 +
''-- prints "1" to the console''}}
 +
 +
{{ScriptFunction|bool|UseGravity |{ get; set; }|Controls whether gravity affects the rigidbody.|5=
 +
 +
local obj = Space.Host.ExecutingObject;<br><br>
 +
''-- Set UseGravity to False (it is set to True by default)''<br>
 +
obj.Rigidbody.UseGravity = false;<br>
 +
''-- Now gravity does not affect the rigidbody.''<br><br>
 +
''-- Get the UseGravity value (find out if UseGravity is in action)''<br>
 +
Space.Log(obj.Rigidbody.UseGravity);<br>
 +
''-- prints "False" to the console''}}
  
 
{{Scripting Navbox}}
 
{{Scripting Navbox}}

Revision as of 20:46, 16 July 2017

The Rigidbody class works with the physics of the object. Requires the Rigidbody component to function.

Properties

AngularDrag

float AngularDrag { get; set; }

The angular drag of the object.

local obj = Space.Host.ExecutingObject;

-- Set a new angular drag value
obj.Rigidbody.AngularDrag = 0.20;

-- Get the current angular drag value
Space.Log(obj.Rigidbody.AngularDrag);

-- prints "0.200000..." to the console



AngularVelocity

SVector AngularVelocity { get; set; }

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

local obj = Space.Host.ExecutingObject;

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

-- Get the current angular velocity value
Space.Log(obj.Rigidbody.AngularVelocity);

-- prints "[0, 3.141593, 0]" to the console



CenterOfMass

SVector CenterOfMass { get; set; }

The center of mass relative to the local origin.

local obj = Space.Host.ExecutingObject;

-- Set a new center of mass
obj.Rigidbody.CenterOfMass = Vector.New(1,0,0);
-- Now the object's center of mass has been moved by 1 at the X axis

-- Get the current center of mass
Space.Log(obj.Rigidbody.CenterOfMass);

-- prints "[1, 0, 0]" to the console



Drag

float Drag { get; set; }

The drag of the object.

local obj = Space.Host.ExecutingObject;

-- Set a new drag value
obj.Rigidbody.Drag = 20;
-- Now the object's drag is set to 20 - the higher the number, the more it is resistant to gravity

-- Get the current drag value
Space.Log(obj.Rigidbody.Drag);

-- prints "20" to the console



FreezeRotation

bool FreezeRotation { get; set; }

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

local obj = Space.Host.ExecutingObject;

-- Set FreezeRotation to True
obj.Rigidbody.FreezeRotation = true;
-- Now under no circumstances the object's rotation coordinates will change.

-- Get the FreezeRotation value (find out if Freeze Rotation is in action)
Space.Log(obj.Rigidbody.FreezeRotation);

-- prints "True" to the console


Kinematic

bool Kinematic { get; set; }

Controls whether physics will have any impact on the object.

local obj = Space.Host.ExecutingObject;

-- Set Kinematic to True
obj.Rigidbody.Kinematic = true;
-- Now the object will not be affected by gravity, collisions, or other forces.

-- Get the Kinematic value (find out if Kinematic is in action)
Space.Log(obj.Rigidbody.Kinematic);

-- prints "True" to the console


Mass

float Mass { get; set; }

The mass of the rigidbody.

local obj = Space.Host.ExecutingObject;

-- Set a new mass of the rigidbody
obj.Rigidbody.Mass = 0.1;

-- Get the current value of the rigidbody's mass
Space.Log(obj.Rigidbody.Mass);

-- prints "0.1000000..." to the console


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.

local obj = Space.Host.ExecutingObject;

-- Set a new value for the maximum angular velocity
obj.Rigidbody.MaxAngularVelocity = 1;
-- Now the object, for example, is more resistant to rolling over upon collision with another object.

-- Get the current value of the rigidbody's maximum angular velocity
Space.Log(obj.Rigidbody.MaxAngularVelocity);

-- prints "1" to the console



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.

local obj = Space.Host.ExecutingObject;

-- Set a new value for the maximum depenetration velocity
obj.Rigidbody.MaxDepenetrationVelocity = 1;

-- Get the current value of the rigidbody's maximum depenetration velocity
Space.Log(obj.Rigidbody.MaxDepenetrationVelocity);

-- prints "1" to the console


UseGravity

bool UseGravity { get; set; }

Controls whether gravity affects the rigidbody.

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