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.
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!
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)
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)-- 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.
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
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
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
local obj = Space.Host.ExecutingObject;obj.Rigidbody.CenterOfMass = Vector.New(1,1,1);Space.Log(obj.Rigidbody.CenterOfMass);-- prints "[1,1,1]" to the consoleobj.Rigidbody.ResetCenterOfMass();Space.Log(obj.Rigidbody.CenterOfMass);-- prints "[0,0,0]" to the console
local obj = Space.Host.ExecutingObject;-- Set a new angular velocity vectorobj.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 vectorSpace.Log(obj.Rigidbody.AngularVelocity);-- prints "[0, 3.141593, 0]" to the console
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 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
local obj = Space.Host.ExecutingObject;-- Set a new velocity vectorobj.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 vectorSpace.Log(obj.Rigidbody.Velocity);-- prints "[0, 0, 1]" to the console
local obj = Space.Host.ExecutingObject;-- Get the current center of massSpace.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.
local obj = Space.Host.ExecutingObject;obj.Rigidbody.Sleep();Space.Log(obj.Rigidbody.Sleeping);-- prints "True" to the consoleobj.Rigidbody.WakeUp();Space.Log(obj.Rigidbody.Sleeping);-- prints "False" to the console
Density
float Densityset
The density of the object (1 by default). Changing this value will affect the mass of the object (the volume will remain unchanged).
density = Space.Host.ExecutingObject.Rigidbody.Density
local obj = Space.Host.ExecutingObject;Space.Log(obj.Rigidbody.Mass);-- prints "1" to the consoleobj.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.
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.
solid = Space.Scene.Find("Solid")--get rigidbody of inertia frame.rigid = solid.Rigidbodyif rigid ==nilthen rigid = solid.AddRigidbody()endrigid.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.