#include #include #include namespace kurator { namespace sim { void FloatingMovement::update(State& ctx) { auto view = ctx.registry.view(); for (auto&& [entity, transform, movement, ai] : view.each()) { const auto offset = ai.destination - transform.position; const auto at_destination = offset.magnitude() > movement.destination_boundary; const auto acceleration = at_destination ? offset.normalized().scale(movement.acceleration * ctx.clock.dt) : offset.normalized().scale(-1 * movement.deceleration * ctx.clock.dt); movement.speed.x += acceleration.x; movement.speed.y += acceleration.y; if (movement.speed.magnitude() > movement.max_speed) movement.speed = movement.speed.normalized().scale(movement.max_speed); const auto speed = movement.speed.scale(ctx.clock.dt); transform.position.x += speed.x; transform.position.y += speed.y; transform.angle = speed.angle(); } } } // namespace sim } // namespace kurator