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 / syncing multiplayer with AI

Author
Message
Mychal B
15
Years of Service
User Offline
Joined: 21st Jul 2010
Location: Coos bay, rainville
Posted: 1st Jun 2012 09:52 Edited at: 1st Jun 2012 16:35
Hey guys,

I just recently took the dive into multiplayer. So far I can connect the games, transfer data, and all of that good stuff. I recently ran into a problem with the AI though.

FYI: I'm using Dark Ai

Problem: when the ai entities interact with each other "collide" there isn't any way of telling how long they will collide for or which direction they will go, and this throws all of the positioning off between computers.

Solution?: The only thing I could think of was only have the server handle the ai, then send out messages to all players of the enemy coordinates. Only problem with that is that it would be a lot of information to pass and may have a delay.

Do you guys have any other solutions that you can think of? Thanks.


SOLVED: What I ended up doing was storing all of my information in a memblock, which contained an id for the packet,object number, and object coordinates. I also set up the message updates to be on a timer so I could fine tune performance over lag. When the messages were received they would update all clients to the servers enemy positions. in between the message updates I would record the speed of the server enemy object for the enemy, send over the one packet, and apply this speed to correctly jump forward all of my enemies. "they all have the same speed" If you guys have any questions let me know

The fastfood zombie killer
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 1st Jun 2012 11:12
Quote: "The only thing I could think of was only have the server handle the ai, then send out messages to all players of the enemy coordinates."


That's the standard way of doing things. The server must be the ultimate authority, otherwise you'll have all kinds of inconsistencies between clients.



Support a charitable indie game project!
Mychal B
15
Years of Service
User Offline
Joined: 21st Jul 2010
Location: Coos bay, rainville
Posted: 1st Jun 2012 12:14
hmmm, It just seems like there should/could be a better way

The fastfood zombie killer
Benjamin
23
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 1st Jun 2012 12:42
I suppose you could do it a little differently depending on the mechanics of the game, but any important decisions (such as AI behaviour) have to come from a single authority, unless you're willing to have the AI do different things for different clients.

You may find some useful information in this overview of the UE3 networking system: http://udn.epicgames.com/Three/NetworkingOverview.html.



Support a charitable indie game project!
Mychal B
15
Years of Service
User Offline
Joined: 21st Jul 2010
Location: Coos bay, rainville
Posted: 1st Jun 2012 13:17
Wow, that looks like a lot of information. Thanks for the help Benjamin

The fastfood zombie killer
basjak
16
Years of Service
User Offline
Joined: 16th Apr 2010
Location: feel like signing up for mars
Posted: 1st Jun 2012 14:54
Quote: "it would be a lot of information to pass and may have a delay"


create a string "objno,x#,y#,z#,ox,oy,oz,objno,x#,y#,z# ......"

and lower the screen fps a bit for a delay on the screen.

Mychal B
15
Years of Service
User Offline
Joined: 21st Jul 2010
Location: Coos bay, rainville
Posted: 1st Jun 2012 15:12
I just started using memblocks to pass the information and so far im LOVING it. Thanks for the tip though

The fastfood zombie killer
Non Sequitur M
17
Years of Service
User Offline
Joined: 28th Oct 2008
Location: Where am I!? Where are YOU?
Posted: 1st Jun 2012 19:23
Did anyone notice the section labeled "Basic Terminology?" Like anyone really reading through that needs that section, or anyone who needs that section will understand the material!

You can speed up transfer by checking which variables have changed, and only send the ones that have, because MP games check thousands of variables every second, but only a fraction of those change. Have your clients programmed so that if a variable isn't received from the server, it's understood by the client to be the same as it was last update.
Mychal B
15
Years of Service
User Offline
Joined: 21st Jul 2010
Location: Coos bay, rainville
Posted: 2nd Jun 2012 01:04
That's a great idea, which I hadn't thought of. Unfortunately that wont help here since the only objects I need to update in real time are enemies and bullets. It's a 3d tower defense game.

As for the Basic Terminology, it done help me learn what a variable is

The fastfood zombie killer
Fallout
23
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 3rd Jun 2012 23:10
Think about what data needs to be sent for a client to work out what to do. For example, when a bullet is fired, do you actually need to send it's position all the time? Or can you just send 1 packet when it's fired and the client can work out the rest? Also if it's a tower defence game and grid based, you only need to send data about the square an object is heading to. The client can perform the movement from square to square itself.

Millenium7
21
Years of Service
User Offline
Joined: 13th Dec 2004
Location:
Posted: 4th Jun 2012 08:26
My way of tackling this problem is to have dummy AI client control. Yes the server will dictate any events that happen, such as AI collision, re-calculating paths, whether it's attacking/moving/defending/whatever. But client's are still able to 'interpolate' between positions and events. I.e.
Server sends:
Position/angle of a newly spawned AI with a timestamp
What it's doing (moving) and where it's going with a timestamp
OPTIONAL: Where it should be in the very near future

You don't need to update the position every loop. Only once in a while, this can dynamically change to accomodate for lag and bandwidth issues. The client's side will use basic AI to ensure those orders are carried out. If it's a simple "unit spawned at XYZ and heading to ABC" then it will only use movement code. It may speed up or slow down the AI slightly to try and keep in sync with the server, but ultimately it doesn't matter. If the AI starts shooting, it will NOT do this on the client's side until 'ordered to' by the server. At which point it will continue to carry out those orders until told differently by the server. You may see some visual discrepencies on the client's side, i.e. an AI unit might suddenly jump from XYZ to ABC and begin shooting if there's a high or fluctuating ping. But at least it ensures consistency

Hopefully that makes some sense.
Mychal B
15
Years of Service
User Offline
Joined: 21st Jul 2010
Location: Coos bay, rainville
Posted: 4th Jun 2012 14:26
Thank you Millenium. That is actually exactly what I ended up doing. I set up a timer that sent over the ai packets "rotation, position, and everything like that" and anything like someone dying or bullets being created was left to be sent instantly. Everything's working how it should

@Fallout: The game isn't grid based. I'm actually trying to take a very unique approach to tower defense. Right now everything is 3d and Once I'm happy with my progress I'll put up a wip. Right now I'm only getting the basic mechanics working "tower upgrades, ai movement, valid locations,networking," but once I'm satisfied with this classic play style I hope to integrate a limited type of first person shooter. While the player will most likely not be able to move around in the tower, he can still take over a character and utilize whatever weapon the tower has to attack the enemy with

The fastfood zombie killer
Hotcrusher1234
15
Years of Service
User Offline
Joined: 11th Jun 2011
Location: Silent Hill
Posted: 5th Jul 2012 17:44
Wait, what I understand is that you put AI in multiplayer??? HOW???

Hotcrusher1234
The Zombie Slayer...
GregA
15
Years of Service
User Offline
Joined: 21st Jun 2011
Location:
Posted: 5th Jul 2012 20:17
I have a side question... Is AI purely deterministic, or is it fuzzy? If I run a simulation with AI more than once, will I get the same result every time?
Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 5th Jul 2012 23:41 Edited at: 5th Jul 2012 23:43
AI is however you program it. Random, or deterministic. There is so far not an AI rule. In the future there may be a rule to AI that simulates real AI. Nobody has figured it out yet, so it is down to the programmer to use his own rules.

BMacZero
20
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 6th Jul 2012 02:36
Just to be clear, this is a BAD idea:
Quote: "create a string "objno,x#,y#,z#,ox,oy,oz,objno,x#,y#,z# ......""

A string representation of a float can (and usually does) have up to 13 characters and an integer can have up to 11. A character takes one byte to transmit (usually), so each float will take about 12 or 13 bytes to transmit (plus a comma). A float itself only requires 4.

Mychal B
15
Years of Service
User Offline
Joined: 21st Jul 2010
Location: Coos bay, rainville
Posted: 11th Jul 2012 03:27
Memblocks are the WAY to go, no joke. It is easy and reduces packet size, meaning faster transfers

The fastfood zombie killer

Login to post a reply

Server time is: 2026-07-07 15:10:35
Your offset time is: 2026-07-07 15:10:35