System that processes heading and rotation physics. More...
Declaration
class helios::engine::modules::physics::motion::systems::SteeringSystem { ... }
Base class
Public Member Functions Index
| void | update (helios::engine::runtime::world::UpdateContext &updateContext) noexcept override |
|
Updates the heading of entities. More...
|
|
Private Member Functions Index
| void | updateHeading (helios::engine::modules::physics::motion::components::SteeringComponent *cmp, float deltaTime) noexcept |
|
Performs the rotation physics update for a SteeringComponent. More...
|
|
Description
System that processes heading and rotation physics.
This system updates the rotation state of entities based on their SteeringComponent. It calculates the target rotation from input, applies rotation speed and dampening, and updates the RotationStateComponent and DirectionComponent.
Definition at line 38 of file SteeringSystem.ixx.
Public Member Functions
update()
Updates the heading of entities.
- Parameters
-
| updateContext | Context containing frame timing and game state. |
Definition at line 120 of file SteeringSystem.ixx.
121
122
123 for (auto [entity, hc, rsc, dc, active] : gameWorld_->view<
128 >().whereEnabled()) {
129
130
131 if (hc->stateChanged()) {
132 auto direction = hc->steeringInput();
134 auto rotationAngleDelta = std::fmod((targetRotationAngle - hc->currentRotationAngle()) + 540.0f, 360.0f) - 180.0f;
135
136 float turnBoostFactor = 0.5f;
137 float turnBoost = 1.0f + turnBoostFactor * std::clamp((abs(rotationAngleDelta))/180.f, 0.0f, 1.0f);
138 float currentRotationSpeed = turnBoost * hc->rotationSpeed() * hc->turnIntensity();
139
140 hc->setTargetRotationAngle(targetRotationAngle);
141 hc->setRotationAngleDelta(rotationAngleDelta);
142 hc->setCurrentRotationSpeed(currentRotationSpeed);
143
144 }
145
146 updateHeading(hc, updateContext.deltaTime());
147
148 float rotationAngle = hc->currentRotationAngle();
149 rsc->setHeadingRotationAngle(rotationAngle);
150 rsc->setHeadingRotationAxis(hc->rotationAxis());
151
153
154 if (hc->directionFromSteering()) {
156 }
157
158
159 }
160
161 }
References helios::math::degrees, helios::engine::ecs::System::gameWorld_ and helios::math::radians.
Private Member Functions
updateHeading()
Performs the rotation physics update for a SteeringComponent.
Applies dampening when input is inactive, calculates rotation steps, and snaps to target when within threshold.
- Parameters
-
| cmp | The SteeringComponent to update. Must not be nullptr. |
| deltaTime | Time elapsed since last frame in seconds. |
Definition at line 51 of file SteeringSystem.ixx.
51 void updateHeading(
53 float deltaTime
54 ) noexcept {
55
56 assert(cmp != nullptr && "Unexpected invalid SteeringComponent passed");
57 assert(deltaTime >= 0 && "Unexpected negative value for deltaTime");
58
59 if (deltaTime == 0) {
60 return;
61 }
62
67
68
69 if (!headingStateChanged) {
71
72 if (currentRotationSpeed < cmp->rotationSpeedThreshold()) {
73 currentRotationSpeed = 0.0f;
74 }
75
77 }
78
79
80 if (currentRotationSpeed > 0.0f) {
81
84
85 } else {
86 float rotationStep = std::copysign(
87 std::min(
88 std::abs(rotationAngleDelta),
89 currentRotationSpeed * deltaTime
90 ),
91 rotationAngleDelta
92 );
93 currentRotationAngle = currentRotationAngle + rotationStep;
94 }
95
96 rotationAngleDelta = std::fmod((cmp->targetRotationAngle() - currentRotationAngle) + 540.0f, 360.0f) - 180.0f;
97
98
99 if (std::abs(rotationAngleDelta) <= 0.5f) {
101 rotationAngleDelta = 0.0f;
102 currentRotationSpeed = 0.0f;
103 }
104
108 }
109
110 }
The documentation for this class was generated from the following file:
Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.