Sign in to follow this  
Vincent_M

Air Hockey-Like Game

Recommended Posts

I'm working on a game similar to air hockey for the iPhone. What happens is there is a puck that is hit back and forth across the playing zone. When the puck gets to the player's side, they must tap it to send it flying in the other direction.

My issue isn't with programming, but on practicality. This game is a speed-based game online. The only crucial data that needs to be sent and received between. What I would like to do is when the puck is hit, I'd send a TCP packet that has the puck's new velocity vector sent to the other player. Now, this puck will be flying in the other direction while the data is being sent. As fast as this puck can get, it could be past the goal by the time the player gets it.

My idea is to use UDP. Each player sends their copy of the puck's position constantly. Then, we the player gets the other player's position, the new position of the puck is the average between the player's local copy and the one off the network.

Does this sound reasonable?

Share this post


Link to post
Share on other sites
Quote:
Original post by Vincent_M
As fast as this puck can get, it could be past the goal by the time the player gets it.

UDP vs. TCP will make no difference in this case.

If there is no packet loss and bandwidth is adequate, TCP and UDP will have similar latency.
If any of those situations do occur, then the problem remains - what happens now? Is the puck paused? Does it jump back? TCP will wait until data is resent. UDP - what to do if packet got lost and player's press never got transmitted. Very frustrating.

The only way to deal with this is to make sure puck cannot travel across the board in less than some minimum time, higher than median network latency. On phones, than can be fairly high.

Share this post


Link to post
Share on other sites
Hmm... I was thinking about keeping the puck stationary until the packet was received too, but then I'd have to send another packet back from the receiver to the sender telling the person received the packet... Maybe, I can figure out an average lag for a game like this, and just pause the ball for the amount of expected lag. This expected lag is a constant.

Share this post


Link to post
Share on other sites
The trick is to fool the user. Simply make the puck move slower after I have hit it on my screen, than it moves on the other players' screen. This means that you will get the return packet from the other player by the time the puck seems to get to the other player on the screen. Then the puck has to move faster to "catch up" to time when you're about to hit it.

On the other player's screen, the same thing happens, in the other direction, of course.

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