Sign in to follow this  
nitin_daviet88

Local Multiplayer gameplay

Recommended Posts

Hey,

I am basically new to iphone game development and have been assigned a task to implement a local Multiplayer option in a car racing game via local wifi network.
i have read many posts still not clear how to do that...basically i want the same multiplayer game play as there in iphone/ipad app Hot pursuit racing game by easports......only two cars need to have race....
what game architecture should i need to follow....?
anyone please guide me to the right direction.......!!!!!!!!

Thanks

Share this post


Link to post
Share on other sites
Have you ever written networking code before?


Start here:

[url="http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/GS_Networking_iPhone/_index.html"]http://developer.app...one/_index.html[/url]

And here:

[url="http://mobileorchard.com/tutorial-networking-and-bonjour-on-iphone/"]http://mobileorchard.com/tutorial-networking-and-bonjour-on-iphone/[/url]

Google is your friend.

Share this post


Link to post
Share on other sites
[quote name='JBourrie' timestamp='1305701557' post='4812297']
Have you ever written networking code before?


Start here:

[url="http://developer.apple.com/library/ios/#referencelibrary/GettingStarted/GS_Networking_iPhone/_index.html"]http://developer.app...one/_index.html[/url]

And here:

[url="http://mobileorchard.com/tutorial-networking-and-bonjour-on-iphone/"]http://mobileorchard...jour-on-iphone/[/url]

Google is your friend.
[/quote]

yes of course written some code ...my one 2d app already live at appstore....
i got this 3d game project all coding part regarding the quick race have already been done by my friend
i have to implement the local multiplayer support to it by my own....any idea how to do that

Share this post


Link to post
Share on other sites
[quote name='torado' timestamp='1305711706' post='4812409']
i got this 3d game project all coding part regarding the quick race have already been done by my friend
i have to implement the local multiplayer support to it by my own....any idea how to do that
[/quote]

First, start with the FAQ for this forum. You can find it at the top.

Second, you should realize that networking is *generally* not something that you just "bolt on" (like, say, some nice particle effects). Instead, successful networked games are designed from the ground up to run the simulation in a way that works well for the latencies involved in networking.

If all you need to support is WiFi for two players, then perhaps you can hack something in, and it might be good enough. However, if you need to support more players, or if you need to support cross-Internet play, then you need to go back and re-architect the simulation, the controls, and even the presentation to support multiplayer racing. (Also: racing games are some of the harder to get right in internet play, the only harder kind I can think of is two-player fighting games)

What I would do if you truly only need support for one local opponent, is to matchmake the players somehow (say, using UDP broadcasts, or use Bonjour if it's available). Then I'd treat each remote player as an AI player on the local system. The trick is that you have to forward extrapolate the remote player by at least one simulation tick -- basically, take the last-received data from the remote player, wind it forward TWO ticks, and make that the "desired target" for the local AI player representing the remote player. There are some more problems, mostly having to do with collisions, where one player detects a collision but the other does not. I would solve these, in the case that you suggest, by each player that detects a collision sending an event to that effect to the other player, and applying the same collision impulse on the other players' machine, even though it will be a tick or two late. And if you detect that a big-crash happens, make sure you synchronize this event, too! This works, as long as you can make sure that nobody cheats by hacking the client. In a local WiFi two-player game iOS, that is usually an OK assumption. For games on the internet, not so much!

Also, WiFi is good because you have a higher data rate. You can send a full rigid body state for each car -- position, orientation, velocity and angular momentum -- for each simulation step. (This is assuming that you're actually doing a physics simulation)

Share this post


Link to post
Share on other sites
[quote name='hplus0603' timestamp='1305730368' post='4812536']
[quote name='torado' timestamp='1305711706' post='4812409']
i got this 3d game project all coding part regarding the quick race have already been done by my friend
i have to implement the local multiplayer support to it by my own....any idea how to do that
[/quote]

First, start with the FAQ for this forum. You can find it at the top.

Second, you should realize that networking is *generally* not something that you just "bolt on" (like, say, some nice particle effects). Instead, successful networked games are designed from the ground up to run the simulation in a way that works well for the latencies involved in networking.

If all you need to support is WiFi for two players, then perhaps you can hack something in, and it might be good enough. However, if you need to support more players, or if you need to support cross-Internet play, then you need to go back and re-architect the simulation, the controls, and even the presentation to support multiplayer racing. (Also: racing games are some of the harder to get right in internet play, the only harder kind I can think of is two-player fighting games)

What I would do if you truly only need support for one local opponent, is to matchmake the players somehow (say, using UDP broadcasts, or use Bonjour if it's available). Then I'd treat each remote player as an AI player on the local system. The trick is that you have to forward extrapolate the remote player by at least one simulation tick -- basically, take the last-received data from the remote player, wind it forward TWO ticks, and make that the "desired target" for the local AI player representing the remote player. There are some more problems, mostly having to do with collisions, where one player detects a collision but the other does not. I would solve these, in the case that you suggest, by each player that detects a collision sending an event to that effect to the other player, and applying the same collision impulse on the other players' machine, even though it will be a tick or two late. And if you detect that a big-crash happens, make sure you synchronize this event, too! This works, as long as you can make sure that nobody cheats by hacking the client. In a local WiFi two-player game iOS, that is usually an OK assumption. For games on the internet, not so much!

Also, WiFi is good because you have a higher data rate. You can send a full rigid body state for each car -- position, orientation, velocity and angular momentum -- for each simulation step. (This is assuming that you're actually doing a physics simulation)
[/quote]

k first thanks for replying ....
hmmm..thats something complex for me....I agree that for a multiplayer game you have to plan from the ground....i started bcoz i thought it might be possible add code for just one opponent... can you please elaborate on " forward extrapolate the remote player by at least one simulation tick " part. i dont have any idea how to that.....any document to start from ?

Share this post


Link to post
Share on other sites
[quote name='torado' timestamp='1305807208' post='4812968']
k first thanks for replying ....
hmmm..thats something complex for me....I agree that for a multiplayer game you have to plan from the ground....i started bcoz i thought it might be possible add code for just one opponent... can you please elaborate on " forward extrapolate the remote player by at least one simulation tick " part. i dont have any idea how to that.....any document to start from ?
[/quote]

Follow the links from my first post. They include full documentation on how to do networking for iPhone: the second link even includes source code for a chat program built using Bonjour. You should be able to take the same concepts and send game data instead of chat data.

[quote name='torado' timestamp='1305807208' post='4812968']
"[color="#1C2837"][size="2"]yes of course written some code ...my one 2d app already live at appstore...."[/size][/color]
[color="#1C2837"][size="2"][/quote][/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]Is it networked? I'm not asking if you've written code, I'm asking if you've written networking code. If so, the links I posted should be a good starting point. If not, you should read up on some game networking theory as well so you understand how to put it all together.[/size][/color]

[quote name='torado' timestamp='1305807208' post='4812968']
"[color="#1C2837"][size="2"]can you please elaborate on " forward extrapolate the remote player by at least one simulation tick " part. i dont have any idea how to that"[/size][/color]
[color="#1C2837"][size="2"][/quote][/size][/color]
[color="#1C2837"] [/color]
[color="#1C2837"][size="2"]All he is really saying is that you need to account for lag by ticking the simulation forward a bit for that vehicle only, so that the opponents car isn't lagging behind on your screen due to the slower network update.[/size][/color]

Share this post


Link to post
Share on other sites
[quote name='JBourrie' timestamp='1305823892' post='4813062']
[size="3"][color="#1C2837"][size=2][/size][/color][/size]
[color="#1C2837"][size="2"]All he is really saying is that you need to account for lag by ticking the simulation forward a bit for that vehicle only, so that the opponents car isn't lagging behind on your screen due to the slower network update.[/size][/color]
[/quote]


I have done that bonjour networking and data sending part...

"ticking the simulation forward a bit" means we have to run the physics code of the other vehicle in our code?

Share this post


Link to post
Share on other sites
[quote name='torado' timestamp='1305869943' post='4813346']
"ticking the simulation forward a bit" means we have to run the physics code of the other vehicle in our code?
[/quote]

Yes, that is one way of doing it.

When you get a new state from the other side, though, you may want to reset the state to that point in time and simulate forward to "now" again. Some kind of interpolation or extrapolation might help smooth out any discontinuities.

Share this post


Link to post
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

Sign in to follow this