]> git.localhorst.tv Git - blank.git/blobdiff - src/ai/ai.cpp
use seconds as world time unit
[blank.git] / src / ai / ai.cpp
index a1abfdc3cf73444102ed63e6210a00b7e2566f1e..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();
@@ -28,10 +28,15 @@ Chaser::~Chaser() {
 }
 
 void Chaser::Update(int dt) {
+       if (Target().Dead()) {
+               Controlled().Kill();
+               return;
+       }
+
        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);
@@ -44,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));
        }
 }
 
@@ -92,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);
        }
 }
@@ -104,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);