class Rigidbody

Inherits: Component

Rigidbody is a dynamic physics object that can be moved using forces (or directly).

It will interact with other static and dynamic physics objects in the scene accordingly (it will push other non-kinematic rigidbodies, and collide with static objects).

The shape and mass of a rigidbody is governed by its colliders. At least one collider must be attached to the collider. To attach a collider, place it on the same scene object as the rigidbody, or a child scene object.

Public

Constructors

Rigidbody

Rigidbody(const HSceneObject &parent)

Methods

Move

void Move(const Vector3 &position)

Moves the rigidbody to a specific position.

This method will ensure physically correct movement, meaning the body will collide with other objects along the way.

Rotate

void Rotate(const Quaternion &rotation)

Rotates the rigidbody.

This method will ensure physically correct rotation, meaning the body will collide with other objects along the way.

SetMass

void SetMass(float mass)

Determines the mass of the object and all of its collider shapes.

Only relevant if RigidbodyFlag::AutoMass or RigidbodyFlag::AutoTensors is turned off. Value of zero means the object is immovable (but can be rotated).

GetMass

float GetMass() const

SetIsKinematic

void SetIsKinematic(bool kinematic)

Determines if the body is kinematic.

Kinematic body will not move in response to external forces (for example gravity, or another object pushing it), essentially behaving like collider. Unlike a collider though, you can still move the object and have other dynamic objects respond correctly (meaning it will push other objects).

GetIsKinematic

bool GetIsKinematic() const

IsSleeping

bool IsSleeping() const

Checks if the body is sleeping.

Objects that aren't moved/rotated for a while are put to sleep to reduce load on the physics system.

Sleep

void Sleep()

Forces the object to sleep.

Useful if you know the object will not move in any significant way for a while.

WakeUp

void WakeUp()

Wakes an object up.

Useful if you modified properties of this object, and potentially surrounding objects which might result in the object being moved by physics (although the physics system will automatically wake the object up for majority of such cases).

SetSleepThreshold

void SetSleepThreshold(float threshold)

Determines a threshold of force and torque under which the object will be considered to be put to sleep.

GetSleepThreshold

float GetSleepThreshold() const

SetUseGravity

void SetUseGravity(bool gravity)

Determines whether or not the rigidbody will have the global gravity force applied to it.

GetUseGravity

bool GetUseGravity() const

SetVelocity

void SetVelocity(const Vector3 &velocity)

Determines the linear velocity of the body.

GetVelocity

Vector3 GetVelocity() const

SetAngularVelocity

void SetAngularVelocity(const Vector3 &velocity)

Determines the angular velocity of the body.

GetAngularVelocity

Vector3 GetAngularVelocity() const

SetDrag

void SetDrag(float drag)

Determines the linear drag of the body.

Higher drag values means the object resists linear movement more.

GetDrag

float GetDrag() const

SetAngularDrag

void SetAngularDrag(float drag)

Determines the angular drag of the body.

Higher drag values means the object resists angular movement more.

GetAngularDrag

float GetAngularDrag() const

SetInertiaTensor

void SetInertiaTensor(const Vector3 &tensor)

Determines the inertia tensor in local mass space.

Inertia tensor determines how difficult is to rotate the object. Values of zero in the inertia tensor mean the object will be unable to rotate around a specific axis. Only relevant if RigidbodyFlag::AutoTensors is turned off.

GetInertiaTensor

Vector3 GetInertiaTensor() const

SetMaxAngularVelocity

void SetMaxAngularVelocity(float velocity)

Determines the maximum angular velocity of the rigidbody.

Velocity will be clamped to this value.

GetMaxAngularVelocity

float GetMaxAngularVelocity() const

SetCenterOfMassPosition

void SetCenterOfMassPosition(const Vector3 &position)

Determines the rigidbody's center of mass position.

Only relevant if RigibodyFlag::AutoTensors is turned off.

GetCenterOfMassPosition

Vector3 GetCenterOfMassPosition() const

SetCenterOfMassRotation

void SetCenterOfMassRotation(const Quaternion &rotation)

Determines the rigidbody's center of mass rotation.

Only relevant if RigibodyFlag::AutoTensors is turned off.

GetCenterOfMassRotation

Quaternion GetCenterOfMassRotation() const

SetPositionSolverCount

void SetPositionSolverCount(u32 count)

Determines the number of iterations to use when solving for position.

Higher values can improve precision and numerical stability of the simulation.

GetPositionSolverCount

u32 GetPositionSolverCount() const

SetVelocitySolverCount

void SetVelocitySolverCount(u32 count)

Determines the number of iterations to use when solving for velocity.

Higher values can improve precision and numerical stability of the simulation.

GetVelocitySolverCount

u32 GetVelocitySolverCount() const

SetCollisionReportMode

void SetCollisionReportMode(CollisionReportMode mode)

Sets a value that determines which (if any) collision events are reported.

GetCollisionReportMode

CollisionReportMode GetCollisionReportMode() const

Gets a value that determines which (if any) collision events are reported.

SetFlags

void SetFlags(RigidbodyFlags flags)

Flags that control the behaviour of the rigidbody.

GetFlags

RigidbodyFlags GetFlags() const

AddForce

void AddForce(const Vector3 &force, ForceMode mode = ForceMode::Force)

Applies a force to the center of the mass of the rigidbody.

This will produce linear momentum.

force
Force to apply.
mode
Determines what is the type of .

AddTorque

void AddTorque(const Vector3 &torque, ForceMode mode = ForceMode::Force)

Applies a torque to the rigidbody.

This will produce angular momentum.

torque
Torque to apply.
mode
Determines what is the type of .

AddForceAtPoint

void AddForceAtPoint(const Vector3 &force, const Vector3 &position, PointForceMode mode = PointForceMode::Force)

Applies a force to a specific point on the rigidbody.

This will in most cases produce both linear and angular momentum.

force
Force to apply.
position
World position to apply the force at.
mode
Determines what is the type of .

GetVelocityAtPoint

Vector3 GetVelocityAtPoint(const Vector3 &point) const

Returns the total (linear + angular) velocity at a specific point.

point
Point in world space.

Returns: Total velocity of the point.

staticGetRttiStatic

static RTTIType *GetRttiStatic()

GetRtti

RTTIType *GetRtti() const override

Returns an interface you can use to access class' Run Time Type Information.

Fields

OnCollisionBegin

Event<void (const CollisionData &)> OnCollisionBegin

Triggered when one of the colliders owned by the rigidbody starts colliding with another object.

OnCollisionStay

Event<void (const CollisionData &)> OnCollisionStay

Triggered when a previously colliding collider stays in collision.

Triggered once per frame.

OnCollisionEnd

Event<void (const CollisionData &)> OnCollisionEnd

Triggered when one of the colliders owned by the rigidbody stops colliding with another object.

Internal

Methods

GetImplementation

IRigidbodyImplementation &GetImplementation() const

Returns the low level rigidbody implementation.

SetParentJoint

void SetParentJoint(const HJoint &joint)

Sets that joint that this rigidbody is attached to.

Allows the rigidbody to notify the joint when it moves.

UpdateMassDistribution

void UpdateMassDistribution()

Recalculates rigidbody's mass, inertia tensors and center of mass depending on the currently set child colliders.

This should be called whenever relevant child collider properties change (like mass or shape).

If automatic tensor calculation is turned off then this will do nothing. If automatic mass calculation is turned off then this will use the mass set directly on the body using SetMass().

Protected

Constructors

Rigidbody

Rigidbody()

Methods

UpdateColliders

void UpdateColliders()

Searches child scene objects for Collider components and attaches them to the rigidbody.

Make sure to call ClearColliders() if you need to clear old colliders first.

ClearColliders

void ClearColliders()

Unregisters all child colliders from the Rigidbody.

AddCollider

void AddCollider(const HCollider &collider)

Registers a new collider with the Rigidbody.

This collider will then be used to calculate Rigidbody's geometry used for collisions, and optionally (depending on set flags) total mass, inertia tensors and center of mass.

RemoveCollider

void RemoveCollider(const HCollider &collider)

Unregisters the collider from the Rigidbody.

CheckForNestedRigibody

void CheckForNestedRigibody()

Checks if the rigidbody is nested under another rigidbody, and throws out a warning if so.

OnCreated

void OnCreated() override

Called once when the component has been created.

Called regardless of the state the component is in.

OnDestroyed

void OnDestroyed() override

Called once just before the component is destroyed.

Called regardless of the state the component is in.

OnDisabled

void OnDisabled() override

Called every time a component is placed into the Stopped state.

This includes component destruction if component wasn't already in Stopped state during destruction. When called during destruction it is called before OnDestroyed.

OnEnabled

void OnEnabled() override

Called every time a component leaves the Stopped state, if the component is enabled.

This includes component creation if requirements for leaving the Stopped state are met. When called during creation it is called after OnBeginPlay.

OnTransformChanged

void OnTransformChanged(TransformChangedFlags flags) override

Called when the component's parent scene object has changed.

Not called if the component is in Stopped state. Also only called if necessary notify flags are set via SetNotifyFlagsInternal().

Fields

mImplementation

UPtr<IRigidbodyImplementation> mImplementation

mChildColliders

Vector<HCollider> mChildColliders

mParentJoint

HJoint mParentJoint

mPositionSolverCount

u32 mPositionSolverCount

mVelocitySolverCount

u32 mVelocitySolverCount

mFlags

RigidbodyFlags mFlags

mCollisionReportMode

CollisionReportMode mCollisionReportMode

mCenterOfMassPosition

Vector3 mCenterOfMassPosition

mCenterOfMassRotation

Quaternion mCenterOfMassRotation

mInertiaTensor

Vector3 mInertiaTensor

mMass

float mMass

mMaxAngularVelocity

float mMaxAngularVelocity

mLinearDrag

float mLinearDrag

mAngularDrag

float mAngularDrag

mSleepThreshold

float mSleepThreshold

mUseGravity

bool mUseGravity

mIsKinematic

bool mIsKinematic