Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Multiplayer Movement

Author
Message
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 26th Nov 2012 14:04 Edited at: 26th Nov 2012 14:06
Hey everybody!

I'm currently implementing multiplayer in my engine. Game instance, developers console, menus, Server, clients, chat... the whole thing works like a charm and now I'm actually working on some objects to represent the players. For now I will use simple spheres that float in space.

I've got the creation and deletion of the spheres (game start/end, client connect,disconnect) working both server and client side. Now for movement!

There are several ways to do this. I will use UDP and provide a constant stream of packets to update the player positions. Now all players will be updated when they receive the packet, but I'm not really sure what to do with the client sending a packet.

Should I update the player object when the data is send (thus right away), or when the data is send back (after response of server)? The first option will allow for instant movement of the character, but the character will react faster than the others. The other method will make all objects be updated at the same time, but the client could experience a lag in their own character movement.

Without going into difficult movement predictions and stuff, what would you recommend or use yourself?

Thanks!

Regards Sph!nx
www.mental-image.net
Darkhog
13
Years of Service
User Offline
Joined: 25th Nov 2012
Location: Mushroom Kingdom
Posted: 26th Nov 2012 14:20
I think you should employ second method along with some linear interpolation of player character (this will help ease lag).

Also you may consider instead of sending constantly positions of players, send keystrokes they make and client would move those players according to keystrokes received.
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 26th Nov 2012 15:03
UDP is good, but only for limited player ammount. every computer needs to handle all online players.
its good for FPS games but not for massive games.
so about the game type you working on.. can you tell me some details?
cuz if its UDP protocol, then you know that the data sending is not reliable - wich means, not 100% will be recived. but UDP DO provide good Ping/ms rate between the players.

so if its FPS kind game, then u should update stuff like:
1) current positions X,Y,Z
2) current rotation Y
3) current animation that playing (when you walking or running)

i think this would be enough for 1 packet.

[http://forum.thegamecreators.com/?m=forum_view&t=201709&b=5]Advanced Updater[/href] for your games!
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 26th Nov 2012 17:07 Edited at: 26th Nov 2012 17:09
Well, it's going to be quite a large game with procedural world generation with NPC and a bunch of players. Though it has nothing to do with blocks and it's a totally different theme it's best compared to minecraft. It's going to be action oriented, but with a relative slow pace.

I know what to update and how to minimise the actual data that gets send/received but I'm wondering at what stage of the data transfer I should update the players.

Regards Sph!nx
www.mental-image.net
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 26th Nov 2012 17:49 Edited at: 26th Nov 2012 17:56
i belive minecraft uses TCP/IP server type. not UDP.

and since you need TCP/IP there is other methods for that..


Edit:

UDP:
since its unrelied protocol, you can send your player positions almost every frame..

TCP/IP:
its lil bit complicated; u NOT actually sending player positions, it works lil bit different, but about 2-3 sends every second

[http://forum.thegamecreators.com/?m=forum_view&t=201709&b=5]Advanced Updater[/href] for your games!
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 26th Nov 2012 18:14
Yeah, I understand TCP and UDP. Most of the data, that is send once, will be TCP, in order without any trouble. The data, like player positions will be a constant stream of packets in UDP.

Good to know that minecraft uses TCP because I was happy with a speed like that but know I know I will probable manage to make it faster with UDP. I think it really doesn't matter when the actual client's player character gets updated. A little trail and error should clear that up.

Thanks Sergey!

Regards Sph!nx
www.mental-image.net
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 26th Nov 2012 18:32
UDP - connects all players to all, so to send data, you need to send it to all players that currently online
so if you have 1000 players online, you will have to send to 1000 of them from client. but what if client's PC is not strong enough for that? it will slow the game a lot.

TCP - you connected only to server.
but server IS connected to everybody else.
so in that case, you need only 1 strong pc to handle the server.

i hope you understand better now the idea of those protocols..

UDP only good for small size of players. such as 16 or even 20
TCP can handle as much as you throw on him as long your server pc will be strong enough.

so if you planning for about ~20 players, UDP is your best choice here..

[http://forum.thegamecreators.com/?m=forum_view&t=201709&b=5]Advanced Updater[/href] for your games!
Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 27th Nov 2012 12:47 Edited at: 27th Nov 2012 12:49
Well, I was aiming for about twenty. I figured the one who would run the server will be able to set that number of course. I was thinking of max. 64 players, but it would be a server admin who decides that.

Still thinking about the right approach. Working on more concept stuff so I get a better picture of all the other data that gets send. TCP is a valid option for my game.

Regards Sph!nx
www.mental-image.net
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 27th Nov 2012 20:36
I am using the following approach in Carnage:

Basic packet logic:
- All UDP. Packet design takes into account for unreliability.
- 'Update' packets have position and state of objects, bullets, logic etc. sent at set rate, up to 10 times per second.
- Additional 'Instant' packets sent for new events (key presses, destruction/creation of objects) as soon as they happen to reduce event lag
- Update packets also contain Instant packet data to get around potential loss of data so events aren't lost.
- Both client and server send at same rate

Movement method:
- Server has responsibility for everything from entity creation (bullets etc) to position and collision. Client also does this stuff but is overridden/updated by server's version.
- All objects have a visual and actual set of positional data. Actual is where the model/entity is and can be updated without interpolation, and Visual is where the visual model is placed and is interpolated towards the Actual data for smoothness.
- Actual positional data is updated instantly by packets, so when the server tells the client a player is at XYZ, Actual data is set straight away.
- Visual positional data is where the model is actually placed and is constantly interpolating towards Actual data. This avoids all jumping and maintains smoothness.

Prediction and input:
- When a player hits a key it is instantly processed client side and updates Actual data. So press forwards and player goes forwards straight away, then sends Instant packet to server.
- When data comes back from server this can override Actual data as normal, so while client key presses have effect straight away, the server has the final word.
- Client also continues to move Actual data of other entities like bullets and players based on their trajectory and simple prediction algorithms if necessary.

The separation of Visual and Actual positional data gives for a really smooth visual representation of the world. To avoid the visual model lagging behind it's actual position you need to get the interpolation right.

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 27th Nov 2012 23:14
It should also be said that time stamping each package allows the client and server to predict things much more easily, because you can take into account the ping delay.

TheComet

Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 28th Nov 2012 08:59
Yep, what he said. 'Actual' position data isn't set to what is received in the packet, it is calculated from position + linear velocity * packet delay.

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 28th Nov 2012 13:38
Wow, thanks guys!

Fallout, you gave me something to ponder over! This is my first (real) attempt at networking and I got everything so far working fine (see previous post).

I will try different things for movement, but basically, each player controls it's own object (directly, client side) then send data to server, data gets send back, other player objects gets updated and if the return packet shows a mismatch on coordinates, the current clients player gets updated as well.

For now, I've stept back from the sphere and will give each client control over his/hers camera and then the data get's send to the server. Just for experimentation purposes. I'll try both UDP and TCP for this.

Thanks again guys!

Regards Sph!nx
www.mental-image.net
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 28th Nov 2012 14:07
A good technique is to add a random lag into your test code (assuming your testing on a LAN or client and server on the same compo). Simulate packets taking a long time to arrive, or arriving out of order, or not arriving at all. Then you'll be in a good place for internet testing.

Sph!nx
17
Years of Service
User Offline
Joined: 3rd Dec 2008
Location: The Netherlands
Posted: 28th Nov 2012 14:23
Thanks for the tip!

Regards Sph!nx
www.mental-image.net

Login to post a reply

Server time is: 2026-07-08 01:54:07
Your offset time is: 2026-07-08 01:54:07