First Person Camera movement replication problem

Hi, I want to create a shooting system for my weapon, but the problem is that on the client the First Person Camera has got a position, while on the server it has got another position.

Blue: client shot
Red: server shot

How can I replicate the camera position on the server?

Is it really that hard to simply replicate the camera position? You’d expect someone to know how to do this and respond by now, but no. Apparently it’s rocket science.

This was asked on Christmas eve, today is boxing day. There are only a few people actually reading the forums right now, I’d say less than 2% of the regular users are here, so it is going to take longer than usual.

With that said, your issue looks like the pitch value from the character/weapon is not being replicated properly, if the gun was perfectly level it would shoot where the red dots are. You have the yaw properly aligned, but not the pitch. I am by no means an expert on replication, but that is where I would be looking.

Sorry I can’t help more than that, but it will take longer than usual to get your answer because of the holidays.

Yes, the pitch of the camera is not replicated, but the yaw is currently replicating only when the player moves (W, A, S, D).

Anyone can help us?

In general any client RPC that is trying to do something like shoot a weapon or do something based on the current view should probably also send the orientation at that moment as part of the function call. This should be the case regardless of whether the orientation is from the camera, the client’s weapon, control rotation, etc. This is how ShooterGame does this (look at ShooterWeapon_Projectile and ShooterWeapon_Instant).

What makes you say that? If PlayerCameraManager bShouldSendClientSideCameraUpdate is true (the default), we send the location as well as yaw and pitch on any frame that bShouldSendClientSideCameraUpdate is true (look at APlayerCameraManager::UpdateCamera). The flag is set in UCharacterMovementComponent::ServerMove(), but that is not called only on WASD movement, it’s called almost every frame. However, this is done as an unreliable function call, so I wouldn’t rely on any important game logic being updated based on the server’s version of the camera.

So I need to use the client side version of the camera for the shooting system?

I solved trace for selection, on server, by doing it from the socket where I have my camera (GetMesh()->GetSocketLocation(“SocketName”)) and at a rotation passed by the input function to the RPC.
The rotation (on client) can be gotten from camera, but I just use GetViewRotation() on pawn in stead…

If people want to make aimbot or whatever, they can already hack rotation through look input, so I would not worry about that.

Yes that’s what I’m suggesting, and what ShooterGame does essentially.

Ok, thanks for the reply and for the help.

No problem, let me know how it goes! Those screenshots leave me wanting to see more :slight_smile:

As of today we are still having issues replicating the camera view in multiplayer. The server is apparently giving a different view from the client, which is a problem. We need this check for security reasons relating to weapons with continuous firing modes such as the Laser Prism.

How could we possibly fix this?

Based on the screenshot, it looks like the version on the right is using the ActorRotation (that has no pitch, only yaw), while the left is using view rotation or controller rotation.

I made replicated variables and I assigned it to FirstPersonCameraComponent->GetComponentLocation(), and FirstPersonCameraComponent->GetComponentRotation() in the Tick event, but I’m getting what Zeb89 said. If I use the timer on the client with that parameters, it works, but I can’t for security purposes. If someone changes the timer on the client, he can change how much the damage is done.

So in your screenshot is the left view the server and right is the client?

Left view is the client and right view is the server (multicast).

Ok, so it sounds like you are not sending the correct rotation from the client to the server.

If the problem is getting it from client->server, a replicated variable won’t work. Replicated variables are only server->client. So you need to use a RPC function to send it from client to server.

It might help to post your setup with a few more details.

The problem is that I need to have the timer on the server, but since the timer is called on the server, I can’t get the parameters from the client.

What would be an example of correctly achieving the desired result?

We need to keep track of where a player is aiming/firing at server side for security reasons since last time we attempted something different, we got cheaters everywhere who were editing the weapons firing rate, etc.

The question is: how Unreal Tournament does this system? The timer of the fire rate must be on server side, and the camera must be updated.