- float dist = dot (diff, diff);
- // TODO: line of sight test
- if (dist > stop_dist) {
- Controlled().Velocity(normalize(diff) * speed);
+ float dist = length(diff);
+ if (dist < std::numeric_limits<float>::epsilon()) {
+ Controlled().TargetVelocity(glm::vec3(0.0f));
+ return;
+ }
+ glm::vec3 norm_diff(diff / dist);
+
+ bool line_of_sight = true;
+ Ray aim{Target().Position() - diff, norm_diff};
+ WorldCollision coll;
+ if (world.Intersection(aim, glm::mat4(1.0f), Target().ChunkCoords(), coll)) {
+ line_of_sight = coll.depth > dist;
+ }
+
+ if (!line_of_sight) {
+ Controlled().TargetVelocity(glm::vec3(0.0f));
+ } else if (dist > stop_dist) {
+ Controlled().TargetVelocity(norm_diff * chase_speed);