Adam's Lair Forum
https://forum.adamslair.net:80/

Movement in a Network Game
https://forum.adamslair.net:80/viewtopic.php?f=14&t=818
Page 1 of 1

Author:  Yothri [ 2016/05/11, 21:39 ]
Post subject:  Movement in a Network Game

Hi,

it's my first time creating a multiplayer game but i am aware of much things that are a no-go in network communication. But i am not sure depending coordinate transfer between the clients.

I am currently writing a 2D Multiplayer game where you can drive and shoot with small tanks.

Now i am not exactly sure on how to realize the movement.
I thought of two methods where i try to avoid one of em...

1: In OnUpdate() when updating the Tanks location, send the new position to server, server will then send the position to all other clients.

Cons: High traffic and it might lag for other clients...

2: If player starts moving, it sends one packet to server that indicates the player started moving. Server then sends one packet to all other clients indicating that the player started moving. Movement packet may contain the speed of the player then.

Pros: Very efficient (low traffic) and impossible to do speedhacks/teleport hacks.

I definately prefer method 2 and already tried to implement it. It works actually, players are updating its locations but i am having issues with the speeds.

Locally in onUpdate() i update the Tanks location with the following code:
TankTransform.Pos += Vector2.FromAngleLength(tankTransform.Angle, Velocity * Time.TimeMult);

Velocity is for testing purposes constantly 5f.

Remote clients will update the remote tanks with the same method, but speeds do not behave same like on local client.

How can i fix this? I thought Time.TimeMult is frame-independant?

Thats what my current problem is, and yeah, movement works actually just fine like this except with that little Speed issue.

I hope someone can help me.

Thanks in advance.

Author:  Yothri [ 2016/05/11, 23:00 ]
Post subject:  Re: Movement in a Network Game

OMG,

NEVER F****N MIND.

I am so stupid, i had changed the speed of my local player in the Editor to a higher value.
Now i reset it and it works perfectly!

Also, the described method 2 is very nice and works perfectly.
Once i did some more efficiency testing i will report you guys back here.

Author:  LehGogh [ 2018/07/01, 06:57 ]
Post subject:  Re: Movement in a Network Game

I'm working on a similar game, and I'm implementing a combination of both. Each packet, I send both absolute position and relative speed. This way, other clients see fully accurate positional data (#1) and has a sort of smoothing for when latency is high (#2). This does add a bit more traffic, but it shouldn't be that bad as long as you rate limit your packets appropriately (e.g. if the game is running at 300fps, don't send 300 packets every second).

Keep in mind that at higher latencies, relying solely on sending velocities will lead to desyncronization as clients change their velocities.

Page 1 of 1 All times are UTC + 1 hour [ DST ]
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/