I'm trying to make a system where a room will do something when the player can see it. However, the camera system means the player can see in all directions simultaneously. How would I go about doing this?
So the room is invisible only from being ocluded by something. You can try raycasting to each of its corners, if one hits it it's visible. If you provide more info about the enviroment we can help better. BTW - how and what are you doing with a 360 view?
The room is fairly complex, but has a relatively small entrance to check through. Before the room's renderer is enabled: (the renderer is meant to be enabled when the room is seen) After: (currently using trigger object) Something to note: The 360 view is what the player object (yellow sphere) "sees"; the actual camera is detached, as was used to take the screenshots. Ignore the excessive gray. I'm still tweaking ambient lighting.
This would probably be more efficiently achieved by collision triggers. Have a child object with a collider and script attached to each "scene module", and in the on trigger enter function enable the parent render's.
That's what I do currently, but that requires either that I spend an eternity calculating where the trigger should go to accurately represent the line of sight or remove the sight check entirely, waiting for the player to enter the area. I did however find a way to cut this down to a small handful of targeted linecasts, targeting the center and each corner of a trigger box in the room's entrance. If any do not hit level geometry, then the room is most likely in sight. It's not foolproof, but it works well enough for my purposes. It still would be nice to know if what I was originally thinking (an object raycasting in a full sphere around it, or a similar method to determine possible line of sight if the object then became oriented correctly) is possible however.
Ok I get ya. Well here is a though. Considering you are gonna be raycasting every physic's frame. It wouldnt be any more intensive to have the ray spinning in a circle.. Like if you have 360 rays going, thats were it would be intensive.. So you can store your rays direction variable in a vector, and every frame rotate by 1 degree. It would still fire fast enough that you wouldn't even notice its not actually firing 360 rays each time. Off the top of my head you should be able to get away with just something like this.. Code (CSharp): dir = new vector3(0,0,(dir.y == 359) ? 0 : diry++); And if you are noticing some latency with the turning, just increment by say 10 instead of 1.
That might work. Another thought to consider: How would you expand it to a sphere rather than a circle?
The same concept, just adjust the x and y values as well. You can do a Debug.DrawRay to preview how it would look like.