I’m making a 3D, first-person game, and I need a way for the game to detect if an object is currently visible in the camera. This is taking into account any wall or barrier obstructing the camera’s view of the target object.
do u use raycast featuer?
https://wiki.gdevelop.io/gdevelop5/extensions/raycaster3d/
I did try the 3D ray cast, specifically “cast ray from camera center”, but the problem is the target object has to actually touch the center of the camera. It’s not a true, “Is it in the camera or not” sorta thing.
I’m also willing to accept some clever work arounds to this. I’ve tried, for example, having a light object work as the player’s vision, but than I couldn’t get the get to detect if an object is actually touching the light. (Simply using collision does not work).
I’ve also thought of making essentially a mesh “emit” out the player, and that mesh would dynamically squish so as to never clip through walls or other obstacles I don’t want it to, but I couldn’t know to begin to do that.
I don’t think there’s a quick solution like placing something covering the whole screen and seeing if it collides in 2D with the 3D object, but you could try.
If that doesn’t work, then you may have to check for collision of the object’s bounding sphere and the camera’s field of view frustum. Search for the term “frustum culling” - it’ll be quite mathematical.
Okay, I’ve got another idea, but I first need a check to see if an object is within the camera’s field of view. I’ve done it before, but annoyingly deleted that code and can’t remember how I did it. Any ideas would be greatly appreciate.
EDIT: I believe I originally did it with 2 angle based conditions, one comparing greater than, one comparing less than. But that’s about it.
UPDATE: I’ve managed to figure an imperfect but functioning system.
For those curious, it’s a 2-3 step process of first detecting if an enemy is in the player’s field of view, then using a 3d ray cast to determine distance from the player while taking walls and stuff into account. Specifically, I set it to detect if the enemies’ distance is below or equal to that of the raycast’s. Then, as an extra provision, I also utilize a general distance from object condition if the raycast isn’t enough.