- float dist = dot (diff, diff);
- // TODO: line of sight test
- if (dist > stop_dist) {
- Controlled().Velocity(normalize(diff) * speed);
+ float dist = length(diff);
+ glm::vec3 norm_diff(diff / dist);
+
+ bool line_of_sight = true;
+ // FIXME: this only works if target is in the reference chunk (which is true for the player)
+ Ray aim{Target().Position() - diff, norm_diff};
+ WorldCollision coll;
+ if (world.Intersection(aim, glm::mat4(1.0f), coll)) {
+ line_of_sight = coll.depth > dist;
+ }
+
+ if (!line_of_sight) {
+ Controlled().Velocity(glm::vec3(0.0f));
+ } else if (dist > stop_dist) {
+ Controlled().Velocity(norm_diff * chase_speed);