Class RigidBody
Physics simulation driven object.
Inherited Members
Assembly: FlaxEngine.dll
File: Engine/Physics/Actors/RigidBody.h
Syntax
public class RigidBody : public Actor, public IPhysicsActor
Fields
_actor
Declaration
protected void* _actor
Field Value
|
void
|
_angularDamping
Declaration
protected float _angularDamping
Field Value
|
float
|
_cachedScale
Declaration
protected Float3 _cachedScale
Field Value
|
Float3
|
_centerOfMassOffset
Declaration
protected Float3 _centerOfMassOffset
Field Value
|
Float3
|
_constraints
_enableGravity
Declaration
protected uint32 _enableGravity
Field Value
|
uint32
|
_enableSimulation
Declaration
protected uint32 _enableSimulation
Field Value
|
uint32
|
_isKinematic
Declaration
protected uint32 _isKinematic
Field Value
|
uint32
|
_isUpdatingTransform
Declaration
protected uint32 _isUpdatingTransform
Field Value
|
uint32
|
_linearDamping
Declaration
protected float _linearDamping
Field Value
|
float
|
_mass
Declaration
protected float _mass
Field Value
|
float
|
_massScale
Declaration
protected float _massScale
Field Value
|
float
|
_maxAngularVelocity
Declaration
protected float _maxAngularVelocity
Field Value
|
float
|
_overrideMass
Declaration
protected uint32 _overrideMass
Field Value
|
uint32
|
_startAwake
Declaration
protected uint32 _startAwake
Field Value
|
uint32
|
_updateMassWhenScaleChanges
Declaration
protected uint32 _updateMassWhenScaleChanges
Field Value
|
uint32
|
_useCCD
Declaration
protected uint32 _useCCD
Field Value
|
uint32
|
CollisionEnter
Occurs when a collision start gets registered for this rigidbody (it collides with something).
Declaration
public Delegate<Collision> CollisionEnter
Field Value
|
Delegate<Collision>
|
CollisionExit
Occurs when a collision end gets registered for this rigidbody (it ends colliding with something).
Declaration
public Delegate<Collision> CollisionExit
Field Value
|
Delegate<Collision>
|
TriggerEnter
Occurs when this rigidbody trigger touching start gets registered for this collider (the other collider enters it and triggers the event).
Declaration
public Delegate<PhysicsColliderActor* > TriggerEnter
Field Value
|
Delegate<PhysicsColliderActor >
|
TriggerExit
Occurs when this rigidbody trigger touching end gets registered for this collider (the other collider enters it and triggers the event).
Declaration
public Delegate<PhysicsColliderActor* > TriggerExit
Field Value
|
Delegate<PhysicsColliderActor >
|
Methods
AddForce(const Vector3& force, ForceMode mode=ForceMode::Force)
Applies a force (or impulse) defined in the world space to the rigidbody at its center of mass.
This will not induce any torque
ForceMode determines if the force is to be conventional or impulsive.
Each actor has an acceleration and a velocity change accumulator which are directly modified using the modes ForceMode::Acceleration and ForceMode::VelocityChange respectively. The modes ForceMode::Force and ForceMode::Impulse also modify these same accumulators and are just short hand for multiplying the vector parameter by inverse mass and then using ForceMode::Acceleration and ForceMode::VelocityChange respectively.
Declaration
public void AddForce(const Vector3& force, ForceMode mode=ForceMode::Force) const
Parameters
|
Vector3
force
The force/impulse to apply defined in the world space. |
|
ForceMode
mode
The mode to use when applying the force/impulse. |
AddForceAtPosition(const Vector3& force, const Vector3& position, ForceMode mode=ForceMode::Force)
Applies a force (or impulse) defined in the world space to the rigidbody at given position in the world space.
Also applies appropriate amount of torque
ForceMode determines if the force is to be conventional or impulsive.
Each actor has an acceleration and a velocity change accumulator which are directly modified using the modes ForceMode::Acceleration and ForceMode::VelocityChange respectively. The modes ForceMode::Force and ForceMode::Impulse also modify these same accumulators and are just short hand for multiplying the vector parameter by inverse mass and then using ForceMode::Acceleration and ForceMode::VelocityChange respectively.
Declaration
public void AddForceAtPosition(const Vector3& force, const Vector3& position, ForceMode mode=ForceMode::Force) const
Parameters
|
Vector3
force
The force/impulse to apply defined in the world space. |
|
Vector3
position
The position of the force/impulse in the world space. |
|
ForceMode
mode
The mode to use when applying the force/impulse. |
AddMovement(const Vector3& translation, const Quaternion& rotation)
Moves the actor (also can rotate it) in world space.
Declaration
public virtual void AddMovement(const Vector3& translation, const Quaternion& rotation) override
Parameters
|
Vector3
translation
The translation vector. |
|
Quaternion
rotation
The rotation quaternion. |
Overrides
AddRelativeForce(const Vector3& force, ForceMode mode=ForceMode::Force)
Applies a force (or impulse) defined in the local space of the rigidbody (relative to its coordinate system) at its center of mass.
This will not induce any torque
ForceMode determines if the force is to be conventional or impulsive.
Each actor has an acceleration and a velocity change accumulator which are directly modified using the modes ForceMode::Acceleration and ForceMode::VelocityChange respectively. The modes ForceMode::Force and ForceMode::Impulse also modify these same accumulators and are just short hand for multiplying the vector parameter by inverse mass and then using ForceMode::Acceleration and ForceMode::VelocityChange respectively.
Declaration
public void AddRelativeForce(const Vector3& force, ForceMode mode=ForceMode::Force) const
Parameters
|
Vector3
force
The force/impulse to apply defined in the local space. |
|
ForceMode
mode
The mode to use when applying the force/impulse. |
AddRelativeTorque(const Vector3& torque, ForceMode mode=ForceMode::Force)
Applies an impulsive torque defined in the local space of the rigidbody (relative to its coordinate system).
ForceMode determines if the force is to be conventional or impulsive.
Each actor has an angular acceleration and an angular velocity change accumulator which are directly modified using the modes ForceMode::Acceleration and ForceMode::VelocityChange respectively.The modes ForceMode::Force and ForceMode::Impulse also modify these same accumulators and are just short hand for multiplying the vector parameter by inverse inertia and then using ForceMode::Acceleration and ForceMode::VelocityChange respectively.
Declaration
public void AddRelativeTorque(const Vector3& torque, ForceMode mode=ForceMode::Force) const
Parameters
|
Vector3
torque
The torque to apply defined in the local space. |
|
ForceMode
mode
The mode to use when applying the force/impulse. |
AddTorque(const Vector3& torque, ForceMode mode=ForceMode::Force)
Applies an impulsive torque defined in the world space to the rigidbody.
ForceMode determines if the force is to be conventional or impulsive.
Each actor has an angular acceleration and an angular velocity change accumulator which are directly modified using the modes ForceMode::Acceleration and ForceMode::VelocityChange respectively.The modes ForceMode::Force and ForceMode::Impulse also modify these same accumulators and are just short hand for multiplying the vector parameter by inverse inertia and then using ForceMode::Acceleration and ForceMode::VelocityChange respectively.
Declaration
public void AddTorque(const Vector3& torque, ForceMode mode=ForceMode::Force) const
Parameters
|
Vector3
torque
The torque to apply defined in the world space. |
|
ForceMode
mode
The mode to use when applying the force/impulse. |
BeginPlay(SceneBeginData* data)
Called when adding object to the game.
Declaration
protected virtual void BeginPlay(SceneBeginData* data) override
Parameters
|
SceneBeginData
data
The initialization data (e.g. used to collect joints to link after begin). |
Overrides
ClosestPoint(const Vector3& position, Vector3& result)
Gets a point on one of the colliders attached to the attached that is closest to a given location. Can be used to find a hit location or position to apply explosion force or any other special effects.
Declaration
public void ClosestPoint(const Vector3& position, Vector3& result) const
Parameters
|
Vector3
position
The position to find the closest point to it. |
|
Vector3
result
The result point on the rigidbody shape that is closest to the specified location. |
Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
Deserializes object from the input stream.
Declaration
public virtual void Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) override
Parameters
|
DeserializeStream
stream
The input stream. |
|
ISerializeModifier
modifier
The deserialization modifier object. Always valid. |
Overrides
EndPlay()
Called when removing object from the game.
Declaration
protected virtual void EndPlay() override
Overrides
GetAngularDamping()
Gets the 'drag' force added to reduce angular movement. Angular damping can be used to slow down the rotation of an object. The higher the drag the more the rotation slows down.
Declaration
public float GetAngularDamping() const
Returns
|
float
|
GetAngularVelocity()
Gets the angular velocity of the rigidbody measured in radians per second.
It's used mostly to get the current angular velocity. Manual modifications may result in unrealistic behaviour.
Declaration
public Vector3 GetAngularVelocity() const
Returns
|
Vector3
|
GetCenterOfMass()
Gets the center of the mass in the local space.
Declaration
public Vector3 GetCenterOfMass() const
Returns
|
Vector3
|
GetCenterOfMassOffset()
Gets the user specified offset for the center of mass of this object, from the calculated location.
Declaration
public Float3 GetCenterOfMassOffset() const
Returns
|
Float3
|
GetColliders(Array<ColliderType* , AllocationType>& result)
Declaration
public void GetColliders(Array<ColliderType* , AllocationType>& result) const
Parameters
|
Array<ColliderType , AllocationType>
result
|
Type Parameters
|
typename ColliderType
|
|
typename AllocationType
|
GetConstraints()
Gets the object movement constraint flags that define degrees of freedom are allowed for the simulation of object.
Declaration
public RigidbodyConstraints GetConstraints() const
Returns
|
RigidbodyConstraints
|
GetEnableGravity()
If object should have the force of gravity applied.
Declaration
public bool GetEnableGravity() const
Returns
|
bool
|
GetEnableSimulation()
If true simulation and collisions detection will be enabled for the rigidbody.
Declaration
public bool GetEnableSimulation() const
Returns
|
bool
|
GetIsKinematic()
Enables kinematic mode for the rigidbody. Kinematic rigidbodies are special dynamic actors that are not influenced by forces(such as gravity), and have no momentum. They are considered to have infinite mass and can push regular dynamic actors out of the way. Kinematics will not collide with static or other kinematic objects but are great for moving platforms or characters, where direct motion control is desired.
Declaration
public bool GetIsKinematic() const
Returns
|
bool
|
GetLinearDamping()
Gets the 'drag' force added to reduce linear movement. Linear damping can be used to slow down an object. The higher the drag the more the object slows down.
Declaration
public float GetLinearDamping() const
Returns
|
float
|
GetLinearVelocity()
Gets the linear velocity of the rigidbody.
It's used mostly to get the current velocity. Manual modifications may result in unrealistic behaviour.
Declaration
public Vector3 GetLinearVelocity() const
Returns
|
Vector3
|
GetMass()
Gets the mass value measured in kilograms (use override value only if OverrideMass is checked).
Declaration
public float GetMass() const
Returns
|
float
|
GetMassScale()
Gets the per-instance scaling of the mass.
Declaration
public float GetMassScale() const
Returns
|
float
|
GetMaxAngularVelocity()
Gets the maximum angular velocity that a simulated object can achieve. The angular velocity of rigidbodies is clamped to MaxAngularVelocity to avoid numerical instability with fast rotating bodies. Because this may prevent intentional fast rotations on objects such as wheels, you can override this value per rigidbody.
Declaration
public float GetMaxAngularVelocity() const
Returns
|
float
|
GetMaxDepenetrationVelocity()
Gets the maximum depenetration velocity when rigidbody moving out of penetrating state.
This value controls how much velocity the solver can introduce to correct for penetrations in contacts. Using this property can smooth objects moving out of colliding state and prevent unstable motion.
Declaration
public float GetMaxDepenetrationVelocity() const
Returns
|
float
The value |
GetOverrideMass()
Override the auto computed mass.
Declaration
public bool GetOverrideMass() const
Returns
|
bool
|
GetPhysicsActor()
Gets the native physics backend object.
Declaration
public virtual void* GetPhysicsActor() const override
Returns
|
void
|
Overrides
GetSleepThreshold()
Gets the mass-normalized kinetic energy threshold below which an actor may go to sleep.
Actors whose kinetic energy divided by their mass is below this threshold will be candidates for sleeping.
Declaration
public float GetSleepThreshold() const
Returns
|
float
The value |
GetStartAwake()
If object should start awake, or if it should initially be sleeping.
Declaration
public bool GetStartAwake() const
Returns
|
bool
|
GetUpdateMassWhenScaleChanges()
If true, it will update mass when actor scale changes.
Declaration
public bool GetUpdateMassWhenScaleChanges() const
Returns
|
bool
|
GetUseCCD()
If true Continuous Collision Detection (CCD) will be used for this component.
Declaration
public bool GetUseCCD() const
Returns
|
bool
|
IsSleeping()
Determines whether this rigidbody is sleeping.
Declaration
public bool IsSleeping() const
Returns
|
bool
|
OnActiveInTreeChanged()
Called when actor active in tree state gets changed.
Declaration
protected virtual void OnActiveInTreeChanged() override
Overrides
OnActiveTransformChanged()
Called when actor's active transformation gets changed after the physics simulation step during.
This event is called internally by the Physics service and should not be used by the others.
Declaration
public virtual void OnActiveTransformChanged() override
Overrides
OnColliderChanged(Collider* c)
OnCollisionEnter(const Collision& c)
OnCollisionExit(const Collision& c)
OnDebugDrawSelected()
Draws debug shapes for the selected actor and all child scripts.
Declaration
public virtual void OnDebugDrawSelected() override
Overrides
OnPhysicsSceneChanged(PhysicsScene* previous)
Declaration
protected virtual void OnPhysicsSceneChanged(PhysicsScene* previous) override
Parameters
|
PhysicsScene
previous
|
Overrides
OnTransformChanged()
Called when actor transform gets changed.
Declaration
protected virtual void OnTransformChanged() override
Overrides
OnTriggerEnter(PhysicsColliderActor* c)
OnTriggerExit(PhysicsColliderActor* c)
Serialize(SerializeStream& stream, const void* otherObj)
Serializes object to the output stream compared to the values of the other object instance (eg. default class object). If other object is null then serialize all properties.
Declaration
public virtual void Serialize(SerializeStream& stream, const void* otherObj) override
Parameters
|
SerializeStream
stream
The output stream. |
|
void
otherObj
The instance of the object to compare with and serialize only the modified properties. If null, then serialize all properties. |
Overrides
SetAngularDamping(float value)
Sets the 'drag' force added to reduce angular movement. Angular damping can be used to slow down the rotation of an object. The higher the drag the more the rotation slows down.
Declaration
public void SetAngularDamping(float value)
Parameters
|
float
value
The value. |
SetAngularVelocity(const Vector3& value)
Sets the angular velocity of the rigidbody measured in radians per second.
It's used mostly to get the current angular velocity. Manual modifications may result in unrealistic behaviour.
Declaration
public void SetAngularVelocity(const Vector3& value) const
Parameters
|
Vector3
value
The value. |
SetCenterOfMassOffset(const Float3& value)
Sets the user specified offset for the center of mass of this object, from the calculated location.
Declaration
public void SetCenterOfMassOffset(const Float3& value)
Parameters
|
Float3
value
|
SetConstraints(const RigidbodyConstraints value)
Sets the object movement constraint flags that define degrees of freedom are allowed for the simulation of object.
Declaration
public void SetConstraints(const RigidbodyConstraints value)
Parameters
|
RigidbodyConstraints
value
|
SetEnableGravity(bool value)
If object should have the force of gravity applied.
Declaration
public void SetEnableGravity(bool value)
Parameters
|
bool
value
|
SetEnableSimulation(bool value)
If true simulation and collisions detection will be enabled for the rigidbody.
Declaration
public void SetEnableSimulation(bool value)
Parameters
|
bool
value
|
SetIsKinematic(const bool value)
Enables kinematic mode for the rigidbody. Kinematic rigidbodies are special dynamic actors that are not influenced by forces(such as gravity), and have no momentum. They are considered to have infinite mass and can push regular dynamic actors out of the way. Kinematics will not collide with static or other kinematic objects but are great for moving platforms or characters, where direct motion control is desired.
Declaration
public void SetIsKinematic(const bool value)
Parameters
|
bool
value
|
SetLinearDamping(float value)
Sets the 'drag' force added to reduce linear movement. Linear damping can be used to slow down an object. The higher the drag the more the object slows down.
Declaration
public void SetLinearDamping(float value)
Parameters
|
float
value
|
SetLinearVelocity(const Vector3& value)
Sets the linear velocity of the rigidbody.
It's used mostly to get the current velocity. Manual modifications may result in unrealistic behaviour.
Declaration
public void SetLinearVelocity(const Vector3& value) const
Parameters
|
Vector3
value
The value. |
SetMass(float value)
Sets the mass value measured in kilograms (use override value only if OverrideMass is checked).
Declaration
public void SetMass(float value)
Parameters
|
float
value
|
SetMassScale(float value)
Sets the per-instance scaling of the mass.
Declaration
public void SetMassScale(float value)
Parameters
|
float
value
|
SetMaxAngularVelocity(float value)
Sets the maximum angular velocity that a simulated object can achieve. The angular velocity of rigidbodies is clamped to MaxAngularVelocity to avoid numerical instability with fast rotating bodies. Because this may prevent intentional fast rotations on objects such as wheels, you can override this value per rigidbody.
Declaration
public void SetMaxAngularVelocity(float value)
Parameters
|
float
value
|
SetMaxDepenetrationVelocity(const float value)
Sets the maximum depenetration velocity when rigidbody moving out of penetrating state.
This value controls how much velocity the solver can introduce to correct for penetrations in contacts. Using this property can smooth objects moving out of colliding state and prevent unstable motion.
Declaration
public void SetMaxDepenetrationVelocity(const float value) const
Parameters
|
float
value
The value. |
SetOverrideMass(bool value)
Override the auto computed mass.
Declaration
public void SetOverrideMass(bool value)
Parameters
|
bool
value
|
SetSleepThreshold(const float value)
Sets the mass-normalized kinetic energy threshold below which an actor may go to sleep.
Actors whose kinetic energy divided by their mass is below this threshold will be candidates for sleeping.
Declaration
public void SetSleepThreshold(const float value) const
Parameters
|
float
value
The value. |
SetSolverIterationCounts(int32 minPositionIters, int32 minVelocityIters)
Sets the solver iteration counts for the rigidbody.
The solver iteration count determines how accurately joints and contacts are resolved. If you are having trouble with jointed bodies oscillating and behaving erratically, then setting a higher position iteration count may improve their stability.
If intersecting bodies are being depenetrated too violently, increase the number of velocity iterations. More velocity iterations will drive the relative exit velocity of the intersecting objects closer to the correct value given the restitution.
Default: 4 position iterations, 1 velocity iteration.
Declaration
public void SetSolverIterationCounts(int32 minPositionIters, int32 minVelocityIters) const
Parameters
|
int32
minPositionIters
The minimum number of position iterations the solver should perform for this body. |
|
int32
minVelocityIters
The minimum number of velocity iterations the solver should perform for this body. |
SetStartAwake(bool value)
If object should start awake, or if it should initially be sleeping.
Declaration
public void SetStartAwake(bool value)
Parameters
|
bool
value
|
SetUpdateMassWhenScaleChanges(bool value)
If true, it will update mass when actor scale changes.
Declaration
public void SetUpdateMassWhenScaleChanges(bool value)
Parameters
|
bool
value
|
SetUseCCD(const bool value)
If true Continuous Collision Detection (CCD) will be used for this component.
Declaration
public void SetUseCCD(const bool value)
Parameters
|
bool
value
|
Sleep()
Forces a rigidbody to sleep (for at least one frame).
Declaration
public void Sleep() const
UpdateBounds()
Updates the bounding box.
Declaration
public void UpdateBounds()
UpdateMass()
Updates the actor's mass (auto calculated mass from density and inertia tensor or overriden value).
Declaration
public void UpdateMass()
UpdateScale()
Updates the rigidbody scale dependent properties like mass (may be modified when actor transformation changes).
Declaration
public void UpdateScale()
WakeUp()
Forces a rigidbody to wake up.
Declaration
public void WakeUp() const