Blueprints - Rotation of pawn is only set on first call
I had another question in the past. Short version: "How the heck is the pawn-controller-principle working?" You can read the details at the end of this post.
Finally I understood the principles of a pawn, a character and a controller. I got like this:
A Pawn is an accumulation of multiple components, held by a wrapper. A pawn can hold a mesh, a transform component and many more components. A character is a special pawn. Usually, it has a move component and a camera. A controller can possess a character. By this a player can give inputs to the controller that will move the character (or any other pawn).
I had to understand this to set a clients position and rotation on a server and the send the updated values to the client.
But the rotation only gets updated on the first call. This is my blueprint:
In this given BP I set the transform of the player pawn on the listen server as a variable and replicate it. This transform is applied to a client player pawn with a slight modification: the clients yaw rotation value should be 45 degrees lower than the listen servers yaw rotation value.
When I start the game it looks like this and it's correct:
The upper window shows the server preview of the scene. Player possess the PlayerController. On the left you can see the visual representation of the client that spawned. It's yaw value is -45.
But as I move I experience this:
The second player pawn is rotated correctly in the server preview but not on the client. What's wrong with this?
If anyone could give me a hint I'd highly appreciate it.
OLD QUESTION: I'm struggeling with the understanding of CharacterController, Pawn and Character, especially when it comes to networks. Here is what I try to achieve:
Let's imagine a multiplayer scenario. I got a listen server and up to 8 clients. The clients get controlled by the server. On the server I'd like to control a humanoid character in first person view. So he is based on the Character class, that has a camera. His transforms should be provided to the clients. They have to use these transforms to be set to the same position. The rotation will be modified on the client-side. The clients don't input anything. They a just look into the scene (through a camera).
I'm able to set up a custom game with a custom default pawn and custom default character controller via blueprints.
But: What do I have to do to make the clients follow the server? Do I have to spawn a different character controller? What is about spectator pawns? From what class the clients have to derive from? Should I use AIControllers to control the clients?
I'm only working with blueprints due to the inability of reading c++.
Any bit of help is highly appreciated.
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:
Follow this question
Once you sign in you will be able to subscribe for any updates here