31 if (!homingRes || !tfRes || !velRes || !roomRes)
34 auto &homings = homingRes->get();
35 auto &transforms = tfRes->get();
36 auto &vels = velRes->get();
37 auto &rooms = roomRes->get();
40 auto targetView =
_registry.
zipView<Transform, EntityType, Health, RoomId>();
42 for (
auto &&[homing, tf, vel, room] :
_registry.
zipView<Homing, Transform, Velocity, RoomId>()) {
44 float bestDist2 = std::numeric_limits<float>::infinity();
48 for (
auto &&[otf, otype, ohealth, oroom] : targetView) {
49 if (oroom.id != room.id)
60 const float dx = otf.position.
x - tf.position.x;
61 const float dy = otf.position.y - tf.position.y;
62 const float d2 = dx * dx + dy * dy;
63 if (d2 < bestDist2 && d2 <= homing.range * homing.range) {
65 targetPos.x = otf.position.x;
66 targetPos.y = otf.position.y;
75 rtp::Vec2f desired =
rtp::Vec2f{targetPos.
x - tf.position.x, targetPos.y - tf.position.y}.normalized();
77 if (vel.speed > 0.0f) {
84 const float t = std::min(1.0f, homing.steering * dt);
86 vel.direction = newDir;
89 const float currSpeed = vel.direction.
length();
90 rtp::Vec2f currDir = currSpeed == 0.0f ? desired : vel.direction / currSpeed;
91 const float t = std::min(1.0f, homing.steering * dt);
93 vel.direction = newDir * currSpeed;