I should add scenario works fine on player char but not my npc’s
None of the answers are correct, the one very important thing to understand to realize the issue/solution is the player control rotation, in a multiplayer game only the server and locally controlled player are aware of this rotation value, locally controlled is the human player with a controller such as a keyboard, mouse etc.
The actual player (local controller) is the one moving the mouse so obviously this player is already able to access the player controller rotation, this value is also automatically transmitted to the server using the CharacterMovement component therefore no need for you to call in any server RPC to update the server about it, since the server has access to this value it is the server who needs to replicate it to other players except the local controlled who originally created this control rotation using a mouse/controller.
The proper way of replicating this control rotation is to use a a replicated variable that skips the owner (owner=local controller)
The skip owner indicates that the local player will not receive updates about this value, and the good thing about replicated variables is that even if you set them in a event tick they’re not immediately replicated the moment they’re set thus managing bandwidth pretty well by the server.
To know if a player is locally controlled you can either check if the character is locally controlled or the player controller is local controller, again local controller means it’s controlled by a keyboard mouse etc on your own device.
So this is the way I would go about it:
If it’s the server or the actual player we set the control rotation in a variable, the server will replicate it to other players but skipping the locally controlled player who created that rotation in the first place, the local player will also set that variable by themselves because they don’t need it replicated they can access the value immediately, and then the value will be used to get the Yaw and pitch by the local player, the server and on other clients for the replicated version of your character on their devices.
Hopefully this makes sense.
Here’s the solution for C++
void ACPP_1Character::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (!IsLocallyControlled()) {
FRotator NewRot = FirstPersonCameraComponent->RelativeRotation;
NewRot.Pitch = (uint8)RemoteViewPitch * 360.f / 255.f;
FirstPersonCameraComponent->SetRelativeRotation(NewRot);
}
}
Could someone please explain or direct where I can find what have I done wrong?
Pitch replication works just fine if I Set 2 players(server and client can see each other pitch rotation), but if I run it as a standalone game it does not work…
https://forums.unrealengine.com/development-discussion/blueprint-visual-scripting/10959-aimoffset-pitch-in-multiplayer/page2
You are a freaking legend dude!
*Yeah I know it is 4 years ago… but it does not change the fact!
@Rev0verDrive Is that “RootYaw_Offset” float set somewhere or is it just 0?
Root offset is set in a function executed just prior.
Here’s the pastebin for the function
Local Variables for the function
AnimBP globals for the two functions.
Anim Graph
You are awesome, thank you for your response. This works perfect!