]> git.localhorst.tv Git - blank.git/blobdiff - src/ai/ai.cpp
use seconds as world time unit
[blank.git] / src / ai / ai.cpp
index d50aee5b6219aa06f170bc86b3f03eb0fb1cf7e3..7dfe0424c44a210cdf1f1619063a2d756da45f64 100644 (file)
@@ -16,8 +16,8 @@ Chaser::Chaser(World &world, Entity &ctrl, Entity &tgt) noexcept
 : Controller(ctrl)
 , world(world)
 , tgt(tgt)
-, chase_speed(0.002f)
-, flee_speed(-0.005f)
+, chase_speed(2.0f)
+, flee_speed(-5.0f)
 , stop_dist(10)
 , flee_dist(5) {
        tgt.Ref();
@@ -36,7 +36,7 @@ void Chaser::Update(int dt) {
        glm::vec3 diff(Target().AbsoluteDifference(Controlled()));
        float dist = length(diff);
        if (dist < std::numeric_limits<float>::epsilon()) {
-               Controlled().Velocity(glm::vec3(0.0f));
+               Controlled().TargetVelocity(glm::vec3(0.0f));
                return;
        }
        glm::vec3 norm_diff(diff / dist);
@@ -49,13 +49,13 @@ void Chaser::Update(int dt) {
        }
 
        if (!line_of_sight) {
-               Controlled().Velocity(glm::vec3(0.0f));
+               Controlled().TargetVelocity(glm::vec3(0.0f));
        } else if (dist > stop_dist) {
-               Controlled().Velocity(norm_diff * chase_speed);
+               Controlled().TargetVelocity(norm_diff * chase_speed);
        } else if (dist < flee_dist) {
-               Controlled().Velocity(norm_diff * flee_speed);
+               Controlled().TargetVelocity(norm_diff * flee_speed);
        } else {
-               Controlled().Velocity(glm::vec3(0.0f));
+               Controlled().TargetVelocity(glm::vec3(0.0f));
        }
 }
 
@@ -97,10 +97,10 @@ void RandomWalk::Update(int dt) {
                Change();
        } else if (lerp_time > 0) {
                float a = std::min(lerp_time / lerp_max, 1.0f);
-               Controlled().Velocity(mix(target_vel, start_vel, a));
+               Controlled().TargetVelocity(mix(target_vel, start_vel, a));
                Controlled().AngularVelocity(mix(target_rot, start_rot, a));
        } else {
-               Controlled().Velocity(target_vel);
+               Controlled().TargetVelocity(target_vel);
                Controlled().AngularVelocity(target_rot);
        }
 }
@@ -109,7 +109,7 @@ void RandomWalk::Change() noexcept {
        start_vel = target_vel;
        start_rot = target_rot;
 
-       constexpr float base = 0.000001f;
+       constexpr float base = 0.001f;
 
        target_vel.x = base * (random.Next<short>() % 1024);
        target_vel.y = base * (random.Next<short>() % 1024);