From 215c77b9d61ed635176edb86e54c6e87a1315dcf Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Mon, 4 Dec 2017 17:06:24 +0100 Subject: [PATCH] steering tweaks --- src/creature/creature.cpp | 6 ++---- src/creature/goal.cpp | 6 ++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/creature/creature.cpp b/src/creature/creature.cpp index 911d9d0..d7a9724 100644 --- a/src/creature/creature.cpp +++ b/src/creature/creature.cpp @@ -950,10 +950,8 @@ glm::dvec3 Steering::Force(const Situation::State &s) const noexcept { glm::dvec3 diff = s.Position() - other->GetSituation().Position(); if (length2(diff) > max_look * max_look) continue; if (!c.PerceptionTest(other->GetSituation().Position())) continue; - double sep = length(diff) - other->Size() * 0.707 - c.Size() * 0.707; - if (sep < min_dist) { - repulse += normalize(diff) * (1.0 - sep / min_dist); - } + double sep = glm::clamp(length(diff) - other->Size() * 0.707 - c.Size() * 0.707, 0.0, min_dist); + repulse += normalize(diff) * (1.0 - sep / min_dist) * force; } result += repulse; } diff --git a/src/creature/goal.cpp b/src/creature/goal.cpp index bcb1682..3f61e2e 100644 --- a/src/creature/goal.cpp +++ b/src/creature/goal.cpp @@ -384,6 +384,8 @@ void LocateResourceGoal::LocateResource() { } } else { // well, what now? + found = false; + searching = false; } } @@ -451,8 +453,8 @@ void LocateResourceGoal::SearchVicinity() { target_pos = GetSituation().Position(); target_pos[(srf + 0) % 3] += Assets().random.SNorm(); target_pos[(srf + 1) % 3] += Assets().random.SNorm(); - // bias towards current direction - target_pos += glm::normalize(GetSituation().Velocity()) * 0.5; + // bias towards current heading + target_pos += GetSituation().Heading() * 0.5; target_pos = clamp(target_pos, -planet.Radius(), planet.Radius()); GetSteering().GoTo(target_pos); } -- 2.39.2