Player Rotation With Mouse Over Server

Hello,

I’ve been trying to solve this problem for days. I have an authoritative server and I’ve gotten player movement to sync up very well. But when I tried implementing rotating the player with the mouse (FPS Looking). The server and client become incredibly out of sync, even though they are running the same calculations. I pin pointed the problem to the client side prediction of the player rotation. But I’m not sure how the server and client can get different values when running the same calculations.

public void RotatePlayer(float mX)
{      
     xRot += mX * lookSensitivity;     
     transform.rotation = Quaternion.Euler(0, xRot, 0);
}

This is how I rotate the player based on mouse input. Because the client and server are so out of sync, it results in jitters and misinterpretations. I feel like its because the abrupt changes of mouse movement can not be predicted the same was a keyboard movement. Any ideas or examples?

When it comes to rotation, you don’t correct the client at all. You let the client decide its own rotation and just send the result of it to the server. Even in an authoritative setup, yes.

Okay, I will answer this as a question about aimbot prevention, as that is really your main concern.

One thing you can do is to watch for unusual rotations that were triggered without corresponding mouse movement. You can do that check client-side (which can be hacked), or server side (in which case, you’d still beam the mouse position to the server, but just for comparison purposes), or both (if the client check fails, save yourself some bandwidth and don’t bother sending it to the server).

It is possible to get false positives however if your game world includes interactions that can change a player’s rotation without their own input (i.e. collisions, scripted events). In which case, you might wanna get smarter about it, like doing this check only in the event of a successful bullet hit, and maybe even tracking the incidence frequency and raising a red flag over a certain threshold.

And even that is not failsafe, as cheaters could also find a way to manipulate the input.

Take a look at this stackoverflow post for a thorough list (although I’m not sure how many can be applied to Unity): http://stackoverflow.com/questions/960499/how-to-prevent-cheating-in-our-multiplayer-games