Stopping stream if player is not in view

Options
Hello! In my game Shredsauce, players can roam around on skis hitting jumps etc. They can be up to 10 players in a room. There is crazy network lag when a room is full though. I'm trying to improve the performance by removing unnecessary data from being sent over the network.

I'm wondering if there's a way to stop reading the rest of the data stream if the player is not in view and visible to our own camera. Here's some code to show what I mean

        if (stream.isReading) {
            Vector3 position = Vector3.zero;
            float someOtherStateInfo = 0f;

            stream.Serialize(ref position);

            // Check to see if position is visible
            if (IsPositionVisible(position)) {
                // Get rest of state info if visible
                stream.Serialize(ref someOtherStateInfo);

                // Do stuff with the rest of the state info
            }
        }
I can't tell if this actually does anything. I think that the stream has already been sent over the network and that it just isn't reading the rest of the state info. Making this code totally useless. If that is the case, is there a better way to accomplish this? Thanks in advance!

Comments

  • Shredsauce
    Options
    I've got a (possibly ghetto) idea. Please let me know if it's a good idea.

    Each player has two photonviews. One just sends over their position while the other sends the rest of the state info. The other players then use the first photonview's position to check whether or not they should fetch the rest of the state info contained in the second photonview.
  • Tobias
    Options
    Have a look at Interest Groups:
    https://doc.photonengine.com/en-us/pun/current/gameplay/interestgroups

    PUN Classic has a sample in the package, that shows one way to use it.
    You should also have a look at the amount of traffic you're sending. Maybe you can optimize that, too. In doubt, also run your app with the profiler, to get an idea what's taking most time. Lag could be local, too.