RigidBodyComponent struct in Thread
Makes an entity participate in physics simulation via Jolt. Pair with one of the collider components (Box / Sphere / Capsule) to define the shape — without a collider the body defaults to a 1×1×1 box.
Properties — authored
| IsStatic | bool | Immovable level geometry. Mutually exclusive with IsKinematic. Default false. |
| IsKinematic | bool | Moved by script, ignores forces, pushes dynamic bodies. Default false. |
| UseGravity | bool | Apply world gravity each step. Default true. |
| Mass | float | In kg. Default 1.0. |
| Friction | float | 0..1. Default 0.2. |
| Restitution | float | Bounciness 0..1. Default 0.0. |
| LinearDamping | float | Translation drag. Default 0.05. |
| AngularDamping | float | Rotation drag. Default 0.05. |
| Constraints | MotionConstraints | Which world axes the body may still move on — see below. |
Properties — runtime
| BodyId | uint32_t | Jolt body handle. 0xFFFFFFFF until Play starts. |
| AppliedAxes | uint8_t | What the live body was last told its axes were. Not serialized. |
Constraints
Six switches, the same as Unity's, and the same meaning: world axes, not the body's own.
| FreezePositionX / Y / Z | bool | The body may not move along that world axis. |
| FreezeRotationX / Y / Z | bool | The body may not rotate about that world axis. |
upright: true, so the pair cannot be got wrong by hand.auto& rb = entity.GetComponent<Thread::RigidBodyComponent>();
rb.Constraints = Thread::UprightConstraints(); // cannot tip; can still slide and turn
Constraints apply immediately, including while the game is running: the body is asked for its degrees of freedom when it is created, and the scene re-applies whatever changed after that.
IsKinematic and say so.If a body still tips over with rotation frozen, the cause is almost certainly the pairing warned about at the top of this page: an entity carrying both this and a CharacterController has two overlapping bodies shoving each other apart, and no constraint reaches that.
Driving the body from a script
Use PhysicsSystem:
auto& rb = GetComponent<Thread::RigidBodyComponent>();
Thread::PhysicsSystem::AddImpulse(rb.BodyId, Thread::Vec3(0.0f, 5.0f, 0.0f)); // jump
Thread::PhysicsSystem::SetLinearVel(rb.BodyId, Thread::Vec3(0.0f, 0.0f, -3.0f));// constant push
RigidBodyComponent struct w Thread
Włącza encję do symulacji fizyki w Jolt. Połącz z jednym z komponentów collidera (Box / Sphere / Capsule), który określa kształt — bez collidera ciało dostaje domyślny sześcian 1×1×1.
Właściwości — ustawiane
| IsStatic | bool | Nieruchoma geometria poziomu. Wyklucza IsKinematic. Domyślnie false. |
| IsKinematic | bool | Przesuwane skryptem, ignoruje siły, popycha ciała dynamiczne. Domyślnie false. |
| UseGravity | bool | Działa na nie grawitacja świata. Domyślnie true. |
| Mass | float | W kg. Domyślnie 1.0. |
| Friction | float | 0..1. Domyślnie 0.2. |
| Restitution | float | Sprężystość 0..1. Domyślnie 0.0. |
| LinearDamping | float | Opór ruchu postępowego. Domyślnie 0.05. |
| AngularDamping | float | Opór obrotu. Domyślnie 0.05. |
| Constraints | MotionConstraints | W których osiach świata ciało może się jeszcze ruszać — patrz niżej. |
Właściwości — w czasie działania
| BodyId | uint32_t | Uchwyt ciała Jolt. 0xFFFFFFFF do startu Play. |
| AppliedAxes | uint8_t | Jakie osie ostatnio przekazano żywemu ciału. Nie zapisywane. |
Ograniczenia ruchu
Sześć przełączników, jak w Unity, i o tym samym znaczeniu: osie świata, nie własne osie ciała.
| FreezePositionX / Y / Z | bool | Ciało nie może się przesuwać wzdłuż tej osi świata. |
| FreezeRotationX / Y / Z | bool | Ciało nie może się obracać wokół tej osi świata. |
upright: true,
żeby tej pary nie dało się pomylić ręcznie.auto& rb = entity.GetComponent<Thread::RigidBodyComponent>();
rb.Constraints = Thread::UprightConstraints(); // nie przewróci się; nadal sunie i się obraca
Ograniczenia działają od razu, także w trakcie gry: ciało pyta o stopnie swobody przy tworzeniu, a scena ponownie stosuje to, co się potem zmieniło.
IsKinematic i powiedz to wprost.Jeśli ciało nadal się przewraca mimo zablokowanego obrotu, przyczyną jest niemal na pewno para opisana na górze tej strony: encja z tym komponentem i CharacterController ma dwa nachodzące ciała, które się rozpychają, a żadne ograniczenie tego nie dosięga.
Sterowanie ciałem ze skryptu
Użyj PhysicsSystem:
auto& rb = GetComponent<Thread::RigidBodyComponent>();
Thread::PhysicsSystem::AddImpulse(rb.BodyId, Thread::Vec3(0.0f, 5.0f, 0.0f)); // skok
Thread::PhysicsSystem::SetLinearVel(rb.BodyId, Thread::Vec3(0.0f, 0.0f, -3.0f));// stałe pchanie