Accessing Rigidbody

Rigidbody access in scripts

HasRigidbody()

Use this before doing anything physics-driven.

Why: not every entity will have a physics actor (static props, editor-only helpers, etc).

if (!entity.HasRigidbody()) return;

GetRigidbodyVelocity(out v)

Reads the current linear velocity from PhysX.

Vector3 v;
entity.GetRigidbodyVelocity(out v);

SetRigidbodyVelocity(v)

Sets linear velocity directly.

Use this for “authoritative” motion (arcade movement, conveyor belts, knockback). Prefer forces/impulses later if you want mass to matter.

entity.SetRigidbodyVelocity(new Vector3(0, 8, 0)); // pop upward

Note: Don’t call SetRigidbodyVelocity every frame unless you intentionally want to override physics (it will cancel friction/impulses).

TeleportRigidbody(pos, rotDeg)

Warps the physics actor to a new transform pose. Rotation is degrees.

Use for:

  1. respawns

  2. scene loads

  3. hard corrections (netcode)

  4. editor “move to” tools


Rigidbody helper usage

SetRigidbodyAngularVelocity(vec3) sets angular velocity in radians/sec for dynamic, non-kinematic bodies.

GetRigidbodyAngularVelocity(out vec3) reads current angular velocity into out. Returns false if unavailable.

AddRigidbodyForce(vec3) applies continuous force (mass-aware).

AddRigidbodyImpulse(vec3) applies an instant impulse (mass-aware).

AddRigidbodyTorque(vec3) applies continuous torque.

AddRigidbodyAngularImpulse(vec3) applies an instant angular impulse.

SetRigidbodyRotation(vec3 degrees) teleports the rigidbody rotation.

Notes:

  1. These return false if the object has no enabled rigidbody or is kinematic.

  2. Use force/torque for continuous input and impulses for bursty actions.

  3. SetRigidbodyRotation is authoritative; use it sparingly during gameplay.

Last updated

Was this helpful?