How do I replicate my camera rotation?

I’m assuming you’re using blueprint.

If your camera is using the control rotation to figure out which direction to look, the server already knows the camera rotation.

First of, to visualize and make debugging easier, open the character blueprint and add a new static mesh component and attach it to the Camera. Set its static mesh to /Engine/EditorMeshes/MatineeCam_SM.MatineeCam_SM (If you don’t see it, tick “Show Engine Folder” under “View Options” in the content browser. If you play test now, the server will see everyone’s camera.

Player controllers exist on the server and on the owning clients. That is, if there’re 5 clients on a listen server, the server will have 6 player controllers (The 5 clients’ and its own), and each client will have 1 (their own).

The control rotation (basically, where the player’s looking) is replicated from clients to the server.
So on the server you can simply get each client’s pawn’s camera rotation no problem (Granted, of course, that your game is using the control rotation to rotate the camera).

To get them to other player’s, you should create a Rotator variable in the character. Eg. call it LookRotation.
Do NOT mark it as replicated. Replicated variables use guaranteed replication which is slow, and a very bad idea to do each frame.

Instead, you make a MulticastSetLookRotation (custom event) with one input (Rotator), and set replicates to “Multicast”. Make sure that “Reliable” is NOT ticked. Make the MulticastSetLookRotation function set the LookRotation to the input, unless executed on the owning client.

http://i.imgur.com/wccAqTu.png


Then in the Tick event of the character, you make a branch with condition of IsServer.
If server, call MulticastSetLookRotation with the value of the “Get Control Rotation” node.

http://i.imgur.com/4ylvM3y.png

This will call MulticastSetLookRotation on all machines (including the server and the owning client).
So after this call, LookRotation has been replicated to all clients, except the owning client (Due to the branch in MulticastSetLookRotation).

Now, regardless of the Branch node in the Tick event, you set the rotation of the CameraBoom to the received LookRotation, if the character does not belong to the local player.

http://i.imgur.com/6VZoqgd.png

Depending on how you do your camera, you may have to alter it a little, but this example should get you started.


http://i.imgur.com/4X9Jyzk.png

11 Likes