- 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};
+ Chunk *chunk;
+ int blkid;
+ float distance;
+ glm::vec3 normal;
+ if (world.Intersection(aim, glm::mat4(1.0f), chunk, blkid, distance, normal)) {
+ line_of_sight = distance > dist;
+ }
+
+ if (!line_of_sight) {
+ Controlled().Velocity(glm::vec3(0.0f));
+ } else if (dist > stop_dist) {
+ Controlled().Velocity(norm_diff * chase_speed);