Jump to content

General Multiplayer movement speed


Jumbofile

Recommended Posts

I need some help with the concept of limiting movement speed for multiplayer games. 

Current this is my server code (Java)

case "2":
                            player.movePlayer(Integer.parseInt(data[1]));
                            sendPackets(packets.updatePlayerPos(player));
                            break;

This receives the request for a player movement update and then sends the client the new movement coords.

 

This is the client code (GDScript)

func _input(event):
	#move up
	if Input.is_key_pressed(KEY_W):
		client.sendPacket(pDef.movePlayer(1))
	#move left
	elif Input.is_key_pressed(KEY_A):
		client.sendPacket(pDef.movePlayer(2)) 
	#move down
	elif Input.is_key_pressed(KEY_S):
		client.sendPacket(pDef.movePlayer(3))
	#move right
	elif Input.is_key_pressed(KEY_D):
		client.sendPacket(pDef.movePlayer(4))

This chunk of code sends the server the request for a movement change when a button is down, of course this sends the server this packet as fast as your fps.

 

I want to regulate speed on the server side. I cannot think of a way to accomplish this. 

Im not asking for exact code, just concepts. I want to be able to limit speed by an arbitrary value. 

 

Thank you for any help!

Link to comment
Share on other sites

You gotta regulate speed first on the client, and then use the server for corrections. The client and server should both know how fast the player can move from one tile to the other.

 

Outside of that input event you need to check and see if the player is already moving, if so don't send any packets.

 

The server needs to keep track of the last player movement time and if another movement packet comes in too fast send a position correction to the client. The goal is to find a happy medium where the server allows some timing variation due to potential latency and doesn't send corrections but for that variation to be small so speed hacking isn't an issue...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...