3 Replies Latest reply: Nov 20, 2009 8:54 AM by 843853 RSS

    Latency + character animation alising

    843853
      Hello folks,

      I won't loose chance to thank people who helped me in previous discussion about handling map on server, just wonna say "Thanks a lot!"

      Now I come with another questions(in this area I don't have a lot of experience, or better I have never done this)

      Scenario:
      I have implemented server+client(2D map with character on it, able to move). When I click on map, character calculates if there is existing point to the destination and begin to move. I communicate server everytime I pass from tile, sending updateDestination(line, column to which I'm goign to move) and updatePosition(when character reaches next tile) to tile until reaching destination tile. Server after recieving request from client, sends notify to another clients in range, so everyone sees character moving.
      Client A
      For example:
      (this is tiled 2d map, where "1" character, with position (1,1))
      0 0 0 0 0
      0 1 0 0 0
      0 0 0 0 0

      I want to move to position (1,3), so se sequence of messages to server will be the next:
      Time Function
      ==== ==================
      1000 updateDestination(1,2)
      2000 updatePosition(1,2)
      2000 updateDestination(1,3)
      3000 updatePosition(1,3)

      Client B
      This client recieving notifications from server(let's imaging lagless scenario, in which I'm testing now)
      Time Function
      ==== ==================
      1000 handleUpdateDestination() -> ClientA, 1, 2
      2000 handleUpdatePosition() -> ClientA, 1, 2
      2000 handleUpdateDestination() ->ClientA, 1, 3
      3000 handleUpdatePosition() -> ClientA, 1, 3

      After updateDestination and updatePositions was recived, I go to HashMap, where foreign characters are stored, alter their coordinates(only if their timestamp is suitable, aka every 100ms) and do repaint.

      Till now everything is beautiful and my characters are synchronized and I see them moving nicely on map.

      Questions time..
      1) (not very related to what is described above) How often should I check latency? Is there any standart or should I adjust it by several tries?
      2) The main problem that I see in my client architecture, that I don't count latency... Imagine following scenarion:
      ClientA
      Sends everything like in scheme above
      Client B
      Recives messages at following timestamp:
      1000 handleUpdateDestination() -> ClientA, 1, 2
      1500 handleUpdatePosition() -> ClientA, 1, 2 (BECAUSE OF LAG SPIKE, updateDestination message came 500ms late)
      1500 handleUpdateDestination() ->ClientA, 1, 3
      2500 handleUpdatePosition() -> ClientA, 1, 3

      The problem is on step 1, where updateDestination message came 500ms late, but character animation takes exacly 1000ms, so I can't interrupt it's animation, but I also need everything to synchronized..
      There must be solutions to this situation.. I was thinking about one(I want to know if it's correct or not, any suggestions are welcome :P)
      - Get the latency value, let's imagine 450ms
      - Make some calculus about foreign character speed, and update character frame not in 100ms, but in 55ms[Total animation time - ((Latency/Total animation time) * 100)]

      This will create some quicker character animation, but I will avoid teleports.. What you think about it?

      Thanks in advance.
      Serhiy.
        • 1. Re: Latency + character animation alising
          843853
          patriot87 wrote:
          The problem is on step 1, where updateDestination message came 500ms late, but character animation takes exacly 1000ms, so I can't interrupt it's animation, but I also need everything to synchronized..
          There must be solutions to this situation.. I was thinking about one(I want to know if it's correct or not, any suggestions are welcome :P)
          - Get the latency value, let's imagine 450ms
          - Make some calculus about foreign character speed, and update character frame not in 100ms, but in 55ms[Total animation time - ((Latency/Total animation time) * 100)]

          This will create some quicker character animation, but I will avoid teleports.. What you think about it?
          I've seen games that do that. It's pretty comical if you ask me, having your character run around at light speed, wildly flailing his arms. Is it better than teleporting? Maybe.

          It's possible to make teleporting look cool. For instance, in Halo (2, anyway), when playing in co-op mode, if one player gets too far behind the other, he is teleported up to the farther player. But it's not like "one frame he's in this location, and the next frame he's over in this other location." They use a transition animation (your view gets blurred like a ripple effect, and unblurs once you're in the new location) to make it more subtle and graceful.

          If you had the graphics capability to softly transition the graphics, it might look pretty good.
          • 2. Re: Latency + character animation alising
            843853
            I have discussed this issue with one of professors of the university and I think I'll opt to teleportations, if low latency -> skipping some frames..
            • 3. Re: Latency + character animation alising
              843853
              Ups double posted..