Urho.Physics.RigidBody Class

Physics rigid body component.

See Also: RigidBody


public class RigidBody : Component


RigidBodies can be either static or moving. A body is static if its mass is 0, and moving if the mass is greater than 0. Note that the triangle mesh collision shape is not supported for moving objects; it will not collide properly due to limitations in the Bullet library. In this case the convex hull shape can be used instead.

The collision behaviour of a rigid body is controlled by several variables. First, the collision layer and mask define which other objects to collide with: see RigidBody.CollisionLayer and RigidBody.CollisionMask.

By default a rigid body is on layer 1; the layer will be ANDed with the other body's collision mask to see if the collision should be reported. A rigid body can also be set to trigger mode to only report collisions without actually applying collision forces. This can be used to implement trigger areas. Use the RigidBody.SetTrigger method to do this.

Friction, rolling friction and restitution coefficients control how kinetic energy is transferred in the collisions. These are set with the RigidBody.Friction, RigidBody.RollingFriction and RigidBody.Restitution properties.

Note that rolling friction is by default zero, and if you want for example a sphere rolling on the floor to eventually stop, you need to set a non-zero rolling friction on both the sphere and floor rigid bodies.

By default rigid bodies can move and rotate about all 3 coordinate axes when forces are applied. To limit the movement, use RigidBody.SetLinearFactor and RigidBody.SetAngularFactor and set the axes you wish to use to 1 and those you do not wish to use to 0. For example moving humanoid characters are often represented by a capsule shape: to ensure they stay upright and only rotate when you explicitly set the rotation in code, set the angular factor to 0, 0, 0.

To prevent tunneling of a fast moving rigid body through obstacles, continuous collision detection (CCD) can be used. It approximates the object as a swept sphere, but has a performance cost, so it should be used only when necessary. Set the RigidBody.CcdRadius and RigidBody.CcdMotionThreshold properties to non-zero values to enable. To prevent false collisions, the body's actual collision shape should completely contain the radius. The motion threshold is the required motion per simulation step for CCD to kick in: for example a box with size 1 should have motion threshold 1 as well.

All physics calculations are performed in world space. Nodes containing a RigidBody component should preferably be parented to the Scene (root node) to ensure independent motion. For ragdolls this is not absolute, as retaining proper bone hierarchy is more important, but be aware that the ragdoll bones may drift far from the animated model's root scene node.

When several collision shapes are present in the same node, edits to them can cause redundant mass/inertia update computation in the RigidBody. To optimize performance in these cases, the edits can be enclosed between calls to RigidBody.DisableMassUpdate and RigidBody.EnableMassUpdate.

The following example shows how you setup both the rigid body on a node to be a box shape, and how to set it up so it detects collisions:

C# Example

void SetupNode (Node node)
    var body = node.CreateComponent<RigidBody> ();
    body.Mass = 1;
    body.SetKinematic (true);
    var shape = node.CreateComponent<CollisionShape> ();
    shape.SetBox (new Vector3(1,1,1), Vector.Zero, Quaternion.Identity);
    node.NodeCollisionStart += (args) => {
        Console.WriteLine (“Collision with {0}”, args.OtherNode);


Namespace: Urho.Physics
Assembly: Urho (in Urho.dll)
Assembly Versions:

The members of Urho.Physics.RigidBody are listed below.

See Also: Component

Public Constructors

Constructs a new instance of Urho.Physics.RigidBody which is tied to the Application.CurrentContext.
Constructs a new instance of Urho.Physics.RigidBody, given a raw pointer to an unmanaged object
Constructs a new instance of Urho.Physics.RigidBody linked to a specific Context.

Protected Constructors

Empty constructor, chain to this constructor when you provide your own constructor that sets the handle field.

Public Properties

ActiveBoolean. Return whether rigid body is active (not sleeping).
AngularDampingSingle. Return angular velocity damping factor. Or Set angular velocity damping factor.
AngularFactorVector3. Return angular degrees of freedom.
AngularRestThresholdSingle. Return angular velocity deactivation threshold. Or Set angular velocity deactivation threshold.
AngularVelocityVector3. Return angular velocity.
AnisotropicFrictionVector3. Return anisotropic friction.
CcdMotionThresholdSingle. Return continuous collision detection motion-per-simulation-step threshold. Or Set continuous collision detection motion-per-simulation-step threshold. 0 disables, which is the default.
CcdRadiusSingle. Return Continuous Collision Detection (CCD) swept sphere radius. Or Set continuous collision detection swept sphere radius.
CenterOfMassVector3. Return center of mass offset.
CollisionEventModeCollisionEventMode. Return collision event signaling mode. Or Set collision event signaling mode. Default is to signal when rigid bodies are active.
CollisionLayerUInt32. Return collision layer. Or Set collision layer.
CollisionMaskUInt32. Return collision mask. Or Set collision mask.
ContactProcessingThresholdSingle. Return contact processing threshold. Or Set contact processing threshold.
FrictionSingle. Return friction coefficient. Or Set friction coefficient.
GravityOverrideVector3. Return gravity override. If zero (default), uses the physics world's gravity. Or Set gravity override. If zero, uses physics world's gravity.
KinematicBoolean. Controls the Kinematic mode.
LinearDampingSingle. Return linear velocity damping factor. Or Set linear velocity damping factor.
LinearFactorVector3. Return linear degrees of freedom.
LinearRestThresholdSingle. Return linear velocity deactivation threshold. Or Set linear velocity deactivation threshold.
LinearVelocityVector3. Return linear velocity.
MassSingle. Return mass. Or Set mass. Zero mass makes the body static.
PhysicsWorldPhysicsWorld. Return physics world.
PositionVector3. Return rigid body position in world space.
RestitutionSingle. Return restitution coefficient. Or Set restitution coefficient.
RollingFrictionSingle. Return rolling friction coefficient. Or Set rolling friction coefficient.
RotationQuaternion. Return rigid body rotation in world space.
TriggerBoolean. Controls the trigger mode (whether collisions are reported, but no forces are applied).
TypeStringHash. Urho's type system type.
TypeNameString. Urho's low-level type name.
TypeNameStaticString. Urho's low-level type name, accessible as a static method.
TypeStaticStringHash. Urho's low-level type, accessible as a static method.
UseGravityBoolean. Return whether rigid body uses gravity. Or Set whether gravity is applied to rigid body.

Public Methods

Activate rigid body if it was resting.
Add a constraint that refers to this rigid body.
Apply attribute changes that can not be applied immediately. Called after scene load or a network update.
Apply force to center of mass.
ApplyForce(Vector3, Vector3)
Apply force at local position.
Apply impulse to center of mass.
ApplyImpulse(Vector3, Vector3)
Apply impulse at local position.
Apply torque.
Apply torque impulse.
ApplyWorldTransform(Vector3, Quaternion)
Apply new world transform after a simulation step. Called internally.
Disable mass update. Call this to optimize performance when adding or editing multiple collision shapes in the same node.
DrawDebugGeometry(DebugRenderer, Boolean)
Visualize the component as debug geometry.
Re-enable mass update and recalculate the mass/inertia by calling UpdateMass(). Call when collision shape changes are finished.
GetVelocityAtPoint(Vector3) : Vector3
Return linear velocity at local point.
Handle enabled/disabled state change.
Readd rigid body to the physics world to clean up internal state like stale contacts.
Register object factory.
Remove the rigid body.
Remove a constraint that refers to this rigid body.
Reset accumulated forces.
Set angular degrees of freedom. Use 1 to enable an axis or 0 to disable. Default is all axes enabled (1, 1, 1).
Set angular velocity.
Set anisotropic friction.
SetCollisionLayerAndMask(UInt32, UInt32)
Set collision group and mask.
Set linear degrees of freedom. Use 1 to enable an axis or 0 to disable. Default is all axes enabled (1, 1, 1).
Set linear velocity.
Set rigid body position in world space.
Set rigid body rotation in world space.
SetTransform(Vector3, Quaternion)
Set rigid body position and rotation in world space as an atomic operation.
Update gravity parameters to the Bullet rigid body.
Update mass and inertia to the Bullet rigid body.