- Home /
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?
Okay, question: Do you really need the server to 'calculate' the rotation? Can you send the client's rotation to the server ins$$anonymous$$d of mouse position (which is what I assume you are doing)? Server authoritative doesn't necessarily mean you have to process player input server-side. You can do that client-side and have the server only decide on critical events.
You may also want to check if the difference is within an acceptable margin of error (i.e. if the rotation difference is less than 1 euler degree, don't bother correcting client)
$$anonymous$$akes sense and you were right, I was sending mouse position to the server. But what prevent players from hacking their rotation on their end (aimbot) and sending that to the server. Is this something that cannot be prevented?
Answer by fholm · Mar 26, 2014 at 08:17 AM
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.
Answer by taylank · Mar 26, 2014 at 08:09 PM
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
I would say that trying to prevent cheating by checking mouse rotation is to error prone, and even most AAA games don't do this.
Your answer
Follow this Question
Related Questions
Emulating authoritative-client behavior (like NetworkTransform) for SyncVars 0 Answers
How to predict where the ball will fall? 4 Answers
Authoritative Server / Player Communication 1 Answer
Unity networking collisions with client authority 1 Answer
How to make enemy try to predict were object is going and stand in its path ? 0 Answers