Skip to main content

Move2DSystem Class

System that processes 2D movement for entities. More...

Declaration

class helios::engine::modules::physics::motion::systems::Move2DSystem { ... }

Public Member Typedefs Index

usingEngineRoleTag = helios::engine::common::tags::SystemRole

Public Member Functions Index

voidupdate (helios::engine::runtime::world::UpdateContext &updateContext) noexcept

Updates movement for all applicable entities. More...

Private Static Functions Index

static helios::math::vec3fmoveGameObject (helios::engine::modules::physics::motion::components::Move2DComponent *cmp, helios::math::vec3f currentDirection, float deltaTime) noexcept

Computes translation delta for an entity based on its Move2DComponent state. More...

Description

System that processes 2D movement for entities.

This system reads from Move2DComponent and applies physics simulation including velocity integration and dampening when input is inactive.

The system updates TranslationStateComponent with the computed translation changes each frame.

Required components:

  • Move2DComponent (physics configuration and state)
  • DirectionComponent (current movement direction)
  • TranslationStateComponent (receives translation updates)

Definition at line 45 of file Move2DSystem.ixx.

Public Member Typedefs

EngineRoleTag

using helios::engine::modules::physics::motion::systems::Move2DSystem::EngineRoleTag = helios::engine::common::tags::SystemRole

Public Member Functions

update()

void helios::engine::modules::physics::motion::systems::Move2DSystem::update (helios::engine::runtime::world::UpdateContext & updateContext)
inline noexcept

Updates movement for all applicable entities.

For each entity with Move2DComponent, computes translation changes and applies them to the TranslationStateComponent.

Parameters
updateContext

Context containing deltaTime and other frame data.

Definition at line 128 of file Move2DSystem.ixx.

129
130 for (auto [entity, m2d, dc, tsc, active] : updateContext.view<
135 >().whereEnabled()) {
136
137 helios::math::vec3f translationDelta;
138
139 translationDelta = moveGameObject(m2d, dc->direction(), updateContext.deltaTime());
140
141 tsc->translateBy(translationDelta);
142 }
143
144 }

Private Static Functions

moveGameObject()

helios::math::vec3f helios::engine::modules::physics::motion::systems::Move2DSystem::moveGameObject (helios::engine::modules::physics::motion::components::Move2DComponent * cmp, helios::math::vec3f currentDirection, float deltaTime)
inline nodiscard noexcept static

Computes translation delta for an entity based on its Move2DComponent state.

Calculates velocity changes based on input state. When input is active, accelerates in the facing direction. When inactive, applies exponential drag to slow down. Velocity is clamped to maximum speed.

Parameters
cmp

Pointer to the Move2DComponent.

currentDirection

The current direction vector from DirectionComponent.

deltaTime

Frame delta time in seconds.

Returns

Translation delta to apply to the entity this frame.

Definition at line 64 of file Move2DSystem.ixx.

64 [[nodiscard]] static helios::math::vec3f moveGameObject(
66 helios::math::vec3f currentDirection,
67 float deltaTime
68 ) noexcept {
69
70 assert(cmp != nullptr && "Unexpected invalid Move2DComponent passed");
71 assert(deltaTime >= 0 && "Unexpected negative value for deltaTime");
72
73 if (deltaTime == 0) {
74 return helios::math::vec3f{0.0f};
75 }
76
77 bool movementStateChanged = cmp->throttle() > helios::math::EPSILON_LENGTH;
78
79
80 auto velocity = cmp->velocity();
81
82 if (!movementStateChanged) {
83 float movementDampening = cmp->movementDampening();
84
85 // Apply exponential drag when no input is active.
86 // This creates a smooth deceleration effect (velocity approaches zero over time).
87 const float drag = std::pow(movementDampening, deltaTime);
88 velocity = velocity * drag;
89
90 if (velocity.length() <= helios::math::EPSILON_LENGTH) {
91 velocity = {0.0f, 0.0f, 0.0f};
92 }
93
94 } else {
95
96 if (cmp->useInstantAcceleration()) {
97 velocity = currentDirection * cmp->movementSpeed() * cmp->throttle();
98 } else {
99 // Accelerate in the current facing direction.
100 // Uses throttle (input intensity) to scale acceleration.
101 velocity = velocity + (currentDirection * (cmp->movementAcceleration() * cmp->throttle() * deltaTime));
102 }
103
104 }
105
106 // Clamp velocity to maximum speed to prevent unlimited acceleration.
107 if (velocity.length() > cmp->movementSpeed()) {
108 velocity = velocity.normalize() * cmp->movementSpeed();
109 }
110
111 cmp->setVelocity(velocity);
112
113 return (velocity + cmp->inheritedVelocity()) * deltaTime;
114 }

The documentation for this class was generated from the following file:


Generated via doxygen2docusaurus 2.0.0 by Doxygen 1.15.0.