SRigidbody
在此类中AddExplosionForce
- 函数
- Add
Explosion Force - Add
Force - Add
Force At Position - Add
Relative Torque - Add
Torque - Closest
Point On Bounds - Get
Point Velocity - Get
Relative Point Velocity - Move
Position - Move
Rotation - Reset
Center Of Mass - Reset
Intertia Tensor - Sleep
- Wake
Up - Sweep
Test All - 属性
- Angular
Drag - Angular
Velocity - Center
Of Mass - Drag
- Freeze
Rotation - Kinematic
- Mass
- Max
Angular Velocity - Max
Depenetration Velocity - Use
Gravity - Velocity
- World
Center Of Mass - Sleeping
- Density
- Inertia
Tensor - Inertia
Tensor Rotation - Game
Object
| 函数 | AddExplosionForce | Applies a force to a rigidbody that simulates explosion effects. |
| 函数 | AddForce | Adds a force to the Rigidbody that is continuously exerted on it in the given direction. |
| 函数 | AddForceAtPosition | Adds a force to the Rigidbody at a given position (should be within the range of the rigidbody for a realistic result). |
| 函数 | AddRelativeTorque | Adds a torque to the rigidbody relative to the local coordinate system. |
| 函数 | AddTorque | Adds a torque to the rigidbody relative to the global coordinate system. |
| 函数 | ClosestPointOnBounds | Returns the closest point on the bounding box of the attached colliders. |
| 函数 | GetPointVelocity | – |
| 函数 | GetRelativePointVelocity | – |
| 函数 | MovePosition | Moves the rigidbody to position. |
| 函数 | MoveRotation | Rotates the rigidbody to rotation. |
| 函数 | ResetCenterOfMass | Reset the center of mass of the rigidbody. |
| 函数 | ResetIntertiaTensor | Reset the inertia tensor value and rotation. |
| 函数 | Sleep | Forces a rigidbody to sleep. |
| 函数 | WakeUp | Forces a rigidbody to wake up. |
| 函数 | SweepTestAll | Like Rigidbody.SweepTest, but returns all hits. |
| 属性 | AngularDrag | The angular drag of the object. |
| 属性 | AngularVelocity | The angular velocity vector of the rigidbody (in radians per second). |
| 属性 | CenterOfMass | The center of mass relative to the local origin. |
| 属性 | Drag | The drag of the object. |
| 属性 | FreezeRotation | Controls whether physics will have any impact on the rotation of the object. |
| 属性 | Kinematic | Controls whether physics will have any impact on the object. |
| 属性 | Mass | The mass of the rigidbody. |
| 属性 | MaxAngularVelocity | The maximum angular velocity of the rigidbody (7 by default). |
| 属性 | MaxDepenetrationVelocity | The maximum depenetration velocity of the rigidbody (1.00000003318135E+32 by default). |
| 属性 | UseGravity | Controls whether gravity affects the rigidbody. |
| 属性 | Velocity | The velocity vector of the rigidbody. (in units per second). |
| 属性 | WorldCenterOfMass | The center of mass of the rigidbody relative to the global origin (Read Only). |
| 属性 | Sleeping | Is the rigidbody sleeping? |
| 属性 | Density | The density of the object (1 by default). |
| 属性 | InertiaTensor | The diagonal inertia tensor of mass relative to the center of mass. |
| 属性 | InertiaTensorRotation | The rotation of the inertia tensor. |
| 属性 | GameObject | – |
函数
AddExplosionForce
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.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| explosionForce | float | – |
| explosionPosition | SVector | – |
| explosionRadius | float | – |
| upwardsModifier | float | – |
返回值
void
示例
Space.Host.ExecutingObject.Rigidbody.AddExplosionForce (300, Vector.New(0,0,0), 10, 20)
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
Adds a force to the Rigidbody that is continuously exerted on it in the given direction.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| force | SVector | – |
返回值
void
示例
Space.Host.ExecutingObject.Rigidbody.AddForce(Vector.New(0,1,0))
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
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.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| force | SVector | – |
| position | SVector | – |
返回值
void
示例
Space.Host.ExecutingObject.Rigidbody.AddForceAtPosition(Vector.New(1,1,1), Vector.New(0,1,0))
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
Adds a torque to the rigidbody relative to the local coordinate system.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| torque | SVector | – |
返回值
void
示例
Space.Host.ExecutingObject.Rigidbody.AddRelativeTorque(Vector.New(0,1,0))
local obj = Space.Host.ExecutingObject;
obj.Rigidbody.AddRelativeTorque (Vector.New(0,100,0));
-- Now the object spins about its own Y axis
AddTorque
Adds a torque to the rigidbody relative to the global coordinate system.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| torque | SVector | – |
返回值
void
示例
Space.Host.ExecutingObject.Rigidbody.AddTorque(Vector.New(0,1,0))
local obj = Space.Host.ExecutingObject;
obj.Rigidbody.AddTorque (Vector.New(0,100,0));
-- Now the object spins about the global Y axis
ClosestPointOnBounds
Returns the closest point on the bounding box of the attached colliders.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| input | SVector | – |
返回值
SVector
示例
Space.Host.ExecutingObject.Rigidbody.ClosestPointOnBounds(Vector.New(1,1,1))
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
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| worldPoint | SVector | – |
返回值
SVector
示例
Space.Host.ExecutingObject.Rigidbody.GetPointVelocity(Vector.New(0,1,0))
GetRelativePointVelocity
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| point | SVector | – |
返回值
SVector
示例
Space.Host.ExecutingObject.Rigidbody.GetRelativePointVelocity(Vector.New(1,1,1))
MovePosition
Moves the rigidbody to position.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| point | SVector | – |
返回值
void
示例
Space.Host.ExecutingObject.Rigidbody.MovePosition(Vector.New(1,1,1))
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
Rotates the rigidbody to rotation.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| rotation | SQuaternion | – |
返回值
void
示例
Space.Host.ExecutingObject.Rigidbody.MoveRotation(Quaternion.New(0,1,0,0))
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
Reset the center of mass of the rigidbody.
返回值
void
示例
Space.Host.ExecutingObject.Rigidbody.ResetCenterOfMass()
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
Reset the inertia tensor value and rotation.
返回值
void
示例
Space.Host.ExecutingObject.Rigidbody.ResetIntertiaTensor()
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
Forces a rigidbody to sleep.
返回值
void
示例
Space.Host.ExecutingObject.Rigidbody.Sleep()
WakeUp
Forces a rigidbody to wake up.
返回值
void
示例
Space.Host.ExecutingObject.Rigidbody.WakeUp()
SweepTestAll
Like Rigidbody.SweepTest, but returns all hits.
参数
| 名称 | 类型 | 默认值 |
|---|---|---|
| direction | SVector | – |
| distance | float | – |
返回值
SPhysicsHit[]
示例
Space.Host.ExecutingObject.Rigidbody.SweepTestAll(Vector.New(1,0,0) , 20)
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.
属性
AngularDrag
The angular drag of the object.
示例
Space.Host.ExecutingObject.Rigidbody.AngularDrag = 0.20
AngularVelocity
The angular velocity vector of the rigidbody (in radians per second).
示例
Space.Host.ExecutingObject.Rigidbody.AngularVelocity = Vector.New(0,1,0)
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
The center of mass relative to the local origin.
示例
Space.Host.ExecutingObject.Rigidbody.CenterOfMass = Vector.New(1,0,0)
Drag
The drag of the object.
示例
Space.Host.ExecutingObject.Rigidbody.Drag = 5
FreezeRotation
Controls whether physics will have any impact on the rotation of the object.
示例
Space.Host.ExecutingObject.Rigidbody.FreezeRotation = true
Kinematic
Controls whether physics will have any impact on the object.
示例
Space.Host.ExecutingObject.Rigidbody.Kinematic = true
Mass
The mass of the rigidbody.
示例
Space.Host.ExecutingObject.Rigidbody.Mass = 0.1
MaxAngularVelocity
The maximum angular velocity of the rigidbody (7 by default). Can be useful to prevent an object from spinning uncontrollably fast.
示例
Space.Host.ExecutingObject.Rigidbody.MaxAngularVelocity = 1
MaxDepenetrationVelocity
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.
示例
Space.Host.ExecutingObject.Rigidbody.MaxDepenetrationVelocity = 1
UseGravity
Controls whether gravity affects the rigidbody.
示例
Space.Host.ExecutingObject.Rigidbody.UseGravity = true
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
The velocity vector of the rigidbody. (in units per second).
示例
Space.Host.ExecutingObject.Rigidbody.Velocity = Vector.New(0,1,0)
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只读
The center of mass of the rigidbody relative to the global origin (Read Only).
示例
``` WorldCenter = Space.Host.ExecutingObject.Rigidbody.WorldCenterOfMass ```
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只读
Is the rigidbody sleeping?
示例
isSleeping = Space.Host.ExecutingObject.Rigidbody.Sleeping
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
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 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
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.
示例
Space.Host.ExecutingObject.Rigidbody.IntertiaTensor = Vector.New(0,0,0)
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
The rotation of the inertia tensor.
示例
Space.Host.ExecutingObject.Rigidbody.InertiaTensorRotation = Quaternion.New(0,0,0,0)
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只读
示例
theGameObject = Space.Host.ExecutingObject.Rigidbody.GameObject



