25 if (!boomerRes || !tfRes || !velRes)
28 auto &boomers = boomerRes->get();
29 auto &transforms = tfRes->get();
30 auto &vels = velRes->get();
32 for (
auto e : boomers.entities()) {
33 if (!boomers.has(e) || !transforms.has(e) || !vels.has(e))
37 auto &btf = transforms[e];
42 const float dx = btf.position.x - b.startPos.x;
43 const float dy = btf.position.y - b.startPos.y;
44 const float d2 = dx * dx + dy * dy;
45 const float threshold = b.maxDistance * b.maxDistance;
46 if (d2 >= threshold) {
48 log::info(
"Boomerang {} reached maxDistance (d2={} threshold={}), starting return", e.index(), d2, threshold);
56 bool ownerFound =
false;
57 for (
auto pe : transforms.entities()) {
58 if (
static_cast<uint32_t
>(pe.index()) == b.ownerIndex) {
66 log::info(
"Boomerang {} owner not found (ownerIndex={}), despawning", e.index(), b.ownerIndex);
71 const auto &otf = transforms[owner];
72 rtp::Vec2f desired{otf.position.
x - btf.position.x, otf.position.y - btf.position.y};
73 if (bvel.speed > 0.0f) {
74 static_cast<void>(desired.normalize());
75 bvel.direction = desired;
77 const float sp = bvel.direction.length();
80 desired = desired.normalized();
81 bvel.direction = desired;
83 desired = desired.normalized();
84 bvel.direction = desired * sp;
86 log::debug(
"Boomerang {} steering towards owner {}: boomerang=({},{}), owner=({},{}), vel=({},{} )",
87 e.index(), owner.
index(), btf.position.x, btf.position.y, otf.position.x, otf.position.y, bvel.direction.x, bvel.direction.y);