Categories
Game Development

Cheat resistant movement algorithm

I changed the movement algorithm today. Formerly: Client sends inputs (position, rotation, velocity, acceleration, angular rotation). Check each field independently using some pretty loose and generous metrics. Do a raytrace to make sure the client didn’t go through a wall. If any field is off by too much, just use the current values on the […]

I changed the movement algorithm today.

Formerly:

Client sends inputs (position, rotation, velocity, acceleration, angular rotation).
Check each field independently using some pretty loose and generous metrics. Do a raytrace to make sure the client didn’t go through a wall.
If any field is off by too much, just use the current values on the server, and force update the sender.

The problems with that are:
1. Requires a raytrace
2. Easy to cheat
3. Accuracy and visibility of lag depend on the client – slow clients give bad performance

I changed it to:

Client sends inputs (position, rotation, velocity, acceleration, angular rotation).
Clamp the timestamp to a maximum value
Look in the transformation state history to find out where the client was back when they created the packet.
Verify input values with a maximum error of 100 milliseconds. If a value is wrong, set the value to the transformation history value

This is better because:

1. Transformation history lookup is perfectly accurate
2. I can use a tight clamp because of this accuracy, so I don’t need to check for going through walls, since the timestamp is too low to ever go through one anyway.
3. Faster with no raytrace.
4. Performance is always good to other clients, no matter how bad the sender is.

However, it does give worse feel to the sender if they are very slow or lagged. They will warp around occasionally as the server corrects them. The warp is interpolated, but still noticeable.

Leave a Reply

Your email address will not be published. Required fields are marked *