Minimizing lag between host/client

Options
Hey guys, in my game I have spells that are called via RPC then fly forward till they hit something, on hit they check to see if the object has health and if it does the player loses health. Basically, they are slower moving bullets, but some are still quite fast. The problem I'm having is that sometimes it LOOKS like a spell will hit another player, but the hit never registers due to network lag. I'm not sure if the problem is in the RPC call, who is registering the hit, or something else. I know networking will also have a lag built into it, but i'd really like to minimize it as I believe it will be frustrating for players to see that they visually hit something, but the hit never registers.

I saw the script for NetworkRigidBodies and was wondering if something like that might work for me, although my spells nor players use rigidbodies.

Please help!

Comments

  • Trevise
    Options
    Would it be helpful to see code or what? I'd really like any feedback! Is there any example as to how most people should use spells?
  • Tobias
    Options
    Code would not help in this case. What would you show?!
    You are on the right track, kind of. The RPC will always have some lag. You can only try to hide it to some degree.

    PhotonNetwork.time is a synchronized server time. When you send an RPC, we include the time when you send it. To get it, add a final parameter of type PhotonMessageInfo to your RPC method. With that, you can calculate the time between send and execution of the RPC and move the spell forward accordingly. It will pop up a bit further away from the shooting player but be positioned more correctly.

    An RPC does not make PUN send the message right away. It will be buffered until the next package is scheduled to be sent. OnPhotonSerializeView on the other hand gets called right before a new package will be sent. So that had lower "local lag".
    You can modify PUN to send packages more often or directly after an RPC or you might send the "i just shot" into a OnPhotonSerializeView.

    Also, you can delay the spell a bit, locally, after you sent it. Let's say you send it immediately, then wait 100ms and then execute it locally. If you do that all the time, then the RPC has 100ms to travel to the other players and be executed in time.

    It depends on the game you do how much of that you want to implement. At the moment, PUN does not have these things built-in. Sorry.
  • Trevise
    Options
    Yes! Any of those would work better than what I'm currently doing. Do you have an examples laying around for any of the things you listed? I'm getting much more familiar with Unity but I'm still having a bit of a hard time wrapping my head around PUN. I mean I can get things to work, but some of these fine tuning things I just don't know how to code! But I learn fast from examples if you have anything.

    Thank you sooooo much!!
  • Trevise
    Options
    How do I send the "I just shot" into OnPhotonSerializeView? I'd like to try that. The delayed local casting doesn't seem to be quite enough of a fix and the moving the spell forward works okay except at close ranges. I trying to find the right mix to make this work.
  • ... or you might send the "i just shot" into a OnPhotonSerializeView.

    I'm also super curious what this means and how to do it. Are you talking about doing some kind of state checking in OnPhotonSerializeView? I would think that would be inefficient. Maybe I'm not understanding at all. Please elaborate, Tobias. :)
  • Trevise
    Options
    I fixed my issue by just having the client that shot the spells determine if they hit or not. I only use OnPhotonSerializeView for movement and a few animations now.