Constraints
Motory a pružiny
Pohání podporované stupně volnosti omezenou force nebo torquem a změkčuje position correction pomocí native pružin.
Motory jsou solver targets, nikoli teleportace. Výsledný pohyb závisí na mass, inertia, kontaktech, limitech, fixed timestep a dostupném force nebo torque budgetu.
Podpora motorů#
| Typ | Targets | Strength limit | Pružina |
|---|---|---|---|
| Hinge | Velocity v rad/s; position ve stupních | set_motor_max_torque() | set_motor_spring() pro position mode |
| Slider | Velocity v units/s; position ve world units | set_motor_max_force() | set_spring() pro position mode |
| SwingTwist | Samostatný swing/twist velocity a position | Samostatné maximum torques | Samostatné swing/twist motor springs |
| SixDOF | Translation vectors, angular velocity a target orientation | Per-axis force nebo torque | Per-axis motor springs |
| Path | Velocity a position jako distance along path | set_motor_max_force() | set_motor_spring() |
Režimy Hinge a Slider#
- set_motor_velocity() vybere a zapne velocity režim.
- set_motor_position() vybere a zapne position režim.
- enable_motor(false) motor vypne a zachová poslední režim; true jej obnoví.
- Nulový force/torque limit zabrání užitečnému pohonu, i když režim zůstane vybraný.
- V position režimu spring frequency řídí tuhost a damping potlačuje oscilace.
Příklad Hinge#
hinge.set_motor_max_torque(35);
hinge.set_motor_spring(3, 0.8);
hinge.set_motor_position(90); // degrees
// Switch to velocity mode later.
hinge.set_motor_velocity(4); // radians per secondPříklad Slider#
slider.set_motor_max_force(80);
slider.set_spring(3, 0.7);
slider.set_motor_position(1.25); // world units
var state = slider.get_motor_state();SwingTwist a SixDOF#
SwingTwist má samostatné native motory pro swing a twist. SixDOF zpřístupňuje JOLT_MOTOR_OFF, JOLT_MOTOR_VELOCITY, JOLT_MOTOR_POSITION a JOLT_MOTOR_POSITION_VELOCITY pro každou osu včetně společných vector/orientation targets a jednotlivých force/torque limitů.
Pružiny a fixed timestep#
- Distance set_spring() změkčuje korekci směrem k povolenému length range a nepotřebuje motor.
- Pružiny Hinge, Slider, SwingTwist, SixDOF a Path patří position motorům.
- SixDOF limit springs jsou oddělené od motor springs a v Jolt 5.6 podporují jen translation axes.
- Velmi vysoká frequency, nízký damping, velký mass ratio nebo velký fixed_dt mohou mechanismus destabilizovat.
- Laďte s production fixed_dt a realistickými hmotnostmi, ne pomocí neomezené strength.
Ověřené kontrakty operací#
Následující kontrakty rozlišují jednotky, návratové hodnoty, chyby a životnost podle aktuální implementace. Nevynechávej kontrolu výsledku: false, 0 a undefined mohou mít u různých metod odlišný význam.
| Symbol / vlastník | Signatura | Kontrakt operace |
|---|---|---|
| JoltConstraint.enable_motor | JoltConstraint.enable_motor(enabled) | Hinge/Slider/Path: Boolean úspěchu. False vypne motor, true obnoví poslední režim, výchozí zapínaný režim VELOCITY. |
| JoltConstraint.get_motor_state | JoltConstraint.get_motor_state() | Hinge/Slider/Path struct {enabled, mode, target_velocity, target_position, spring_frequency, spring_damping, max_torque|max_force}, undefined při chybě. Hinge velocity rad/s, position °, max_torque N·m; Slider/Path velocity m/s, position m, max_force N. |
| JoltConstraint.set_motor_max_force | JoltConstraint.set_motor_max_force(force) | Pouze Slider/Path: konečný nezáporný limit N, Boolean. |
| JoltConstraint.set_motor_max_torque | JoltConstraint.set_motor_max_torque(torque) | Pouze Hinge: konečný nezáporný limit N·m, Boolean. |
| JoltConstraint.set_motor_position | JoltConstraint.set_motor_position(position) | Hinge: konečný úhel ve stupních; Slider: posun v m; Path: vzdálenost podél cesty v m. Boolean; zapne POSITION motor. |
| JoltConstraint.set_motor_spring | JoltConstraint.set_motor_spring(frequency, damping) | Pouze Hinge/Path: konečné frequency ≥0 Hz a damping ≥0 (poměr); Boolean. Pro Slider použij set_spring. |
| JoltConstraint.set_motor_velocity | JoltConstraint.set_motor_velocity(velocity) | Hinge: konečná rychlost v rad/s; Slider/Path: m/s. Boolean; nastaví cíl a zapne VELOCITY motor. Hinge zde nepoužívá stupně/s. |