Determine if an object is within the field of view of another object?

Using an object’s rotation property, and a given FOV angle, how can I quickly calculate if another object is within that field of view? I’ll be running this function with each animate loop pass so it needs to be very fast.

Please consider that in order to check intersections in 3d you are going to need more than a fov angle. Camera frustum is a 3d volume defined by planes, which you can set with that fov, plus an aspect ratio, and far/near planes.

If a volume like that suits your needs, and If the object you intend to check is a point, you can use frustum.containsPoint() function for a fast enough evaluation

1 Like

Can I do the frustrum processing for other objects in the world, or does it only work for the camera? I have “security drones” exploring my world I want to do the same processing for them so they react when they “see” something.

If so, if I do a lot of “frustrum” processing in my animate loop, for example 3 security drones doing a frustrum check every animate loop, will it be a CPU problem?

Frustum is bound to cameras, so its not available to any other object3D. However, it is simple to place 3 cameras and check for an object visibility using each camera’s frustum.intersectsObject() function, which is based on object’s bounding sphere.

Regarding performance, I think it should not represent a problem, but you will have to check against target hardware/device.

For an out-of-the-box line of sight functionality you could give a try to @Mugen87 excelent yuka library, which inplements a perception mechanism, here there is a demo of it.


Thanks, didn’t even know about that library. I’ll have a look.

On the camera front, does having a lot of camera instances, let’s 20, affect performance significantly.