I'm attempting to do a logic test regarding a client's camera in a multiplayer FPS in Unity and I'm a little uncertain of which way to implement the functionality.
- I have a host and a client playing together.
- I want to be able to tell if specific objects are visible from each player's camera, even on the edges of their screens.
For a local player this is simple, I just take the local camera reference, convert the target object's position to that camera's viewport space to see if it's within the bounds of the camera, and then raycast to test for blocking objects.
In a Host-Client setup, I've been attempting to ensure I do everything on the Host's machine, but the Client's camera does not exist in that context, only a third-person remote-player.
- I could pass the object's position to the client, convert it to the client's viewport space on their machine, then send that converted position back to the Host every frame, but this seems like a lot of network traffic for this. Furthermore it would use a stale client's camera position on the Host's up-to-date object position.
- Or I could do the full logic test on the client machine and only tell the host the result (e.g., success/fail). But from my understanding this is an ill-advised practice given how authority should be handled in a Host-Client setup...
- Or I could keep a camera object on the remote-player and synchronise that with the client's camera position and then do the test solely on the Host's machine involving that synced camera and objects.
I'm not sure which approach to pursue and would appreciate any input!