Local Multiplayer gameplay

Started by
7 comments, last by nitin_daviet88 12 years, 10 months ago
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
Advertisement
Have you ever written networking code before?


Start here:

http://developer.app...one/_index.html

And here:

http://mobileorchard.com/tutorial-networking-and-bonjour-on-iphone/

Google is your friend.

Check out my new game Smash and Dash at:

http://www.smashanddashgame.com/


Have you ever written networking code before?


Start here:

http://developer.app...one/_index.html

And here:

http://mobileorchard...jour-on-iphone/

Google is your friend.


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

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


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)
enum Bool { True, False, FileNotFound };

[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


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 ?

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 ?


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.


"[color="#1C2837"]yes of course written some code ...my one 2d app already live at appstore...."
[color="#1C2837"]

[color="#1C2837"]
[color="#1C2837"]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.


"[color="#1C2837"]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"
[color="#1C2837"]

[color="#1C2837"]
[color="#1C2837"]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.

Check out my new game Smash and Dash at:

http://www.smashanddashgame.com/


[color="#1C2837"][size=2]
[color="#1C2837"]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.



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?

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


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.
enum Bool { True, False, FileNotFound };
k fine totally understood that ...one last thing what about the timestep or dt or delta time ; should it be constant or variable (i.e. depend on the drawing time)....
Regards

This topic is closed to new replies.

Advertisement