Search Unity

Problems with networking visuals & collisions

Discussion in 'Multiplayer' started by Slences, Jul 22, 2015.

  1. Slences

    Slences

    Joined:
    Jul 15, 2015
    Posts:
    4
    I have been playing around with Photon some time now, but I have some major issues and frustrations on how I should achieve something. I'm creating a very simplified version of this. A few things I have implemented so far:

    - Each client can shoot 1 type projectile
    - Each client has attributes
    - Client gets knockbacked on impact & loses health

    The problem however is, when a client spawns a projectile and the projectile hits another player, the visuals seem fine for the instigator, but not for the other client that get hit. This is because I'm not syncing the projectiles' real position over the network, but lerping with:

    transform.position = Vector3.Lerp(transform.position, realPosition, Time.deltaTime * 5);

    When I actually just put the Transform in the PhotonView, the movement will become very laggy but the point of collision is right.

    I'm struggling with how to find a balance between smooth movement and right visuals, how would I achieve this? And is Photon a good choice for this type of games? It seems like everything is a bit off (animations, movement etc) and this was not the case when I tried this using another engine (Unreal Engine 4). I like the API and usability of Unity & Photon way more, but it feels like everything is laggy and off although my connection is just fine.

     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    The problem is exactly what you described: The balance between being late (lagging) and having jagged updates.
    This is the same for pretty much any networking solution, actually. There is no 0 lag magic.
    Maybe Unreal was running locally: One client hosts, one connects to it. Being on the same machine, they have very low delays in communication. But this won't be what you get in the real world, where remote players will fight each other from different locations.

    You have to keep lag to a minimum and then find ways to hide the negative effects of the lag you can't avoid.
    You can even cheat a bit: If the owner of a projectile calculates the hits, you can probably do that a few frames before the actual hit. Send the "projectile will hit" message a few frames early and you hide some more lag.
     
  3. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,913
  4. Slences

    Slences

    Joined:
    Jul 15, 2015
    Posts:
    4
    Well, the thing is, I created a dedicated server and then let a friend (who lives somewhere else) join it, and the collision was actually really accurate. I don't know if it has anything to do with me using the Photon free version though.

    Maybe you get the wrong idea, but what I'm trying to say is that the point of collision is actually a lot different than the instigator. It feels like there is a 200ms difference.
     
  5. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,068
    Photon Free does not have any restrictions, aside from the user cap.

    There is going to be some lag (I don't know your roundtrip times) and there is some internal lag because the clients only send updates every 100ms. It's just 10 updates/sec by default which can't be extremely precise.

    I assume that Unreal Engine used more aggressive settings. It's primarily built for shooters, after all.
    You can try to raise the update rate in PUN. Set PhotonNetworking.sendRateOnSerialize to 20 and check it out.
    Have a look at the roundtrip time with GetPing().