m |
(Added 4 Members: AddExplosionForce, AddForce, AddForceAtPosition, AddTorque) |
||
Line 1: | Line 1: | ||
The Rigidbody class works with the physics of the object. Requires the Rigidbody component to function. | The Rigidbody class works with the physics of the object. Requires the Rigidbody component to function. | ||
+ | |||
+ | ==Members== | ||
+ | |||
+ | {{ScriptFunction|void|AddExplosionForce|(float explosionForce, SVector 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.|5= | ||
+ | |||
+ | local obj = Space.Host.ExecutingObject;<br><br> | ||
+ | obj.Rigidbody.AddExplosionForce (300, obj.WorldPosition, 10, 20)<br> | ||
+ | ''-- The explosion will occur at the location of the ExecutingObject.'' <br> | ||
+ | ''-- Place other rigidbodies around it to observe the effect!''}} | ||
+ | |||
+ | {{ScriptFunction|void|AddForce|(SVector force)|Adds a force to the Rigidbody that is continuously exerted on it in the given direction.|5= | ||
+ | |||
+ | local obj = Space.Host.ExecutingObject;<br><br> | ||
+ | obj.Rigidbody.AddForce (Vector.New(0,100,0));<br> | ||
+ | ''-- Now the rigidbody is under a continuous force directed upwards (Y direction)''}} | ||
+ | |||
+ | {{ScriptFunction|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.|5= | ||
+ | |||
+ | local obj = Space.Host.ExecutingObject;<br> | ||
+ | local applyForceHere = Vector.New(obj.WorldPosition.x-0.5,obj.WorldPosition.y-0.5,obj.WorldPosition.z-0.5)<br> | ||
+ | ''-- This vector is equivalent to one of the lower corners of a 1x1x1 cube.''<br><br> | ||
+ | |||
+ | obj.Rigidbody.AddForceAtPosition (Vector.New(0,40,0), applyForceHere);<br> | ||
+ | ''-- The object is experiencing an effect similar to being tipped upwards at the aforementioned corner.''}} | ||
+ | |||
+ | {{ScriptFunction|void|AddTorque|(SVector force)|Adds a torque to the rigidbody. |5= | ||
+ | |||
+ | local obj = Space.Host.ExecutingObject;<br><br> | ||
+ | obj.Rigidbody.AddTorque (Vector.New(0,100,0));<br> | ||
+ | ''-- Now the object spins about its Y axis''}} | ||
==Properties== | ==Properties== |
The Rigidbody class works with the physics of the object. Requires the Rigidbody component to function.
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.
obj.Rigidbody.AddExplosionForce (300, obj.WorldPosition, 10, 20)
-- The explosion will occur at the location of the ExecutingObject.
Adds a force to the Rigidbody that is continuously exerted on it in the given direction.
obj.Rigidbody.AddForce (Vector.New(0,100,0));
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 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);
Adds a torque to the rigidbody.
obj.Rigidbody.AddTorque (Vector.New(0,100,0));
The angular drag of the object.
-- Set a new angular drag value
obj.Rigidbody.AngularDrag = 0.20;
-- Get the current angular drag value
Space.Log(obj.Rigidbody.AngularDrag);
The angular velocity vector of the rigidbody (in radians per second).
-- 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);
The center of mass relative to the local origin.
-- 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);
The drag of the object.
-- 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);
Controls whether physics will have any impact on the rotation of the object.
-- 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);
Controls whether physics will have any impact on the object.
-- 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);
The mass of the rigidbody.
-- 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);
The maximum angular velocity of the rigidbody (7 by default). Can be useful to prevent an object from spinning uncontrollably fast.
-- 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);
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.
-- 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);
Controls whether gravity affects the rigidbody.
-- 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);
The velocity vector of the rigidbody. (in units per second).
-- 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);
The center of mass of the rigidbody relative to the global origin (Read Only).
-- Get the current center of mass
Space.Log(obj.Rigidbody.WorldCenterOfMass);
|