Hi everyone,
maybe someone of you could help me please. I think I’m in the right location.
I’ve got a problem with a multiplayer scenario. I try to send the position and rotation of a player on a listen server to all clients. Each client will modify the rotation from the server to look in the right direction.
I’ve got this far:
This is the part of the blueprint that (at least that’s my intention) sends the location and rotation of the player pawn at listen server sets it for the player pawns at all clients.
In this case, the client should rotate -45 around his Z-axis (yaw).
The following screenshot shows the state right after spawning:
The rotation of the client is as I wish it to be. It’s rotated -45 degrees around the z-Axis on the server and on the client.
But as a rotate the player pawn on the listen server the clients player pawn is not rotated anymore:
The player pawn on the listen server that is representing the client is rotated correctly.
It seems like the rotation is only set once at the beginning of the “session”.
Can you help me, please?
EDIT: SOLVED!
I got it! Finally! The key component was the replication of the root component of my player character.
I forgot to set the actor root component replication to true. It seems a replication of an actor is not necessarily able to set the rotation of an other actor. The default player pawn of my scene, set in a custom Game Class, contains all logic for the component replication. I made sure the pawn is not rotated by the controller as well as my camera is independent from it.
At “Event Begin Play” I set the replication for the root component, the camera component and a (I guess the right name is) scene component (acting as a child of the root component but as a parent for the camera component) to true.
For the authority in the game: Mouse and keyboard input move the root component of a character “with authority”. So I made sure my whole blueprint is mostly executed on a machine with authority by the node “Switch has Authority”. The root component only gets rotated around its yaw. Only the child scene component gets rotated around pitch and roll. The camera component has a relative rotation of (0; 0; 0), relative to the scene component.
For all remote players: Their location is determined by the authority. So the location of the root component just gets replicated and can be read by the remote clients. Their root component yaw rotation is set by the authority/server. Their scene component pitch and roll rotation is set by the authority, too (based on its pitch and roll). For each remote controlled player in the game, the camera component gets a relative rotation around yaw: Index in array multiplied by 45 (from 45°, I have eight cameras in this scene for a 360 degree projection) and substract 45°, so the second remote player is seeing the same as the server.
In the end not that complicated, if you understand the principles of pawn replication, variable replication and component replication. In this case no pawn replication nor variable replication is set. Only component replication.
This is the final result:
END OF EDIT
Best,
Huppys