Author Topic: Problem with Android hosted LAN game  (Read 2443 times)

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Problem with Android hosted LAN game
« on: August 25, 2015, 09:06:02 AM »
When played over LAN, my game's behaviour is different depending on whether Unity is hosting or an Android device is.

Edit: When hosting on PC, everything is smooth. When hosting on Android, client updates of specific characters doesn't work.

I have the host control all enemies and content. Clients control only their local character. Every 10th of a second, the host sends updates in a batch for enemy positions. These are lerped between network updates for smooth motion. For each player, running the same movement script, they send updates every tenth of a second across the network using

tno.SendQuickly ((byte)GLOBAL.RFCs.CLIENT_UPDATE_CHAR_POS,TNet.Target.Others,intMovingTo, motionDirection);

This works except when hosted on Android (Nexus 7 2013) and two characters move at the same time. In this case, the non-locally controlled character jerks on clients. That is, the host machine sends the client updates for monsters and the other player character. The monsters are smooth, the player character isn't, using exactly the same code. When Unity hosts on PC, it all works fine.
« Last Edit: August 25, 2015, 10:33:27 AM by Shifty Geezer »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Problem with Android hosted LAN game
« Reply #1 on: August 26, 2015, 11:20:16 AM »
SendQuickly uses UDP, which means unreliable packets. They are not guaranteed to arrive, and not all devices support it, especially mobiles. UDP traffic is often quite restricted by carriers if not outright blocked. LAN should work fine, but again mobile devices often end up batching frequent updates into infrequent bursts. Regular tno.Send uses TCP, so it's guaranteed to arrive. I suggest you rethink whether you need to send updates so frequently. Using prediction/interpolation will save bandwidth if nothing else.

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Re: Problem with Android hosted LAN game
« Reply #2 on: August 28, 2015, 07:24:06 AM »
Turns out it's some weird issue with InvokeRepeating not behaving the same as FixedUpdate. I moved this sync code out of FixedUpdate() so I could run the physics faster, and the behaviour on Android changed as a result. Moving it back into FixedUpdate and only applying every other update solves this for now until I really understand what's happening.

It's a LAN (or Wifi) only game so I'm happy with my net design.