X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fai%2Fai.cpp;h=7dfe0424c44a210cdf1f1619063a2d756da45f64;hb=4da2ae6f12d7cf4594edb2d560c5c112e9bcd094;hp=a1abfdc3cf73444102ed63e6210a00b7e2566f1e;hpb=e57cc01be658357de5829fae655ae52309e83743;p=blank.git diff --git a/src/ai/ai.cpp b/src/ai/ai.cpp index a1abfdc..7dfe042 100644 --- a/src/ai/ai.cpp +++ b/src/ai/ai.cpp @@ -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::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() % 1024); target_vel.y = base * (random.Next() % 1024);