[Released] Saving traffic. Movement bots. PUN

An effective synchronization of large PUN bots number movement.

Document description: What does the message consist of? Packages, commands, limits, message queues.

Network gameplay with bots example (based on the package SurvivalShooter (UnityEssentials example))

Release :

My account at Asset Store -The Best Assets for Game Making | Unity Asset Store

Download pc build :

So we’re watching at a co-op where the bots are sync from the master client?

Yes. Most important is how it synchronizes

I’ve seen in Russian and English forums the PhotonCloud is not understanding how to synchronize a large number of objects. The difficulty is that the limits of transmitted traffic per second, after which queues come and packets are transmitted with a delay, it’s quite early. Very “severe” limits =)

If you synchronize scene objects in the usual way (one object = one PhotonView - OnPhotonSerializeView (position transfer))
In the region of 35-45 pieces, movement lags will begin. (Queue of the transfer of packages of positions)
If they also perform some kind of behavior and it certainly needs to be transmitted over the network, then normal synchronization without lags is approximately in the region of 5-15 pieces, depending on how often this behavior is updated in a second.

My option allows you to increase the maximum limit many times. I showed the video “MoveBots”.

To the package AssetStore added documentation in which I disassembled topics that answer the question why my method is so many times reducing traffic

3019530--225538--upload_2017-4-4_19-30-14.png

Awesome, I definitely need to give this a look as the message limit is a bit painful certainly. I’m busy for next 8 weeks but definitely bookmarked.

I’ve got a tank game running, so, per tank:
*Body translation rotation
*Turret rotation
*Cannon rotation

Plus I’ve some teleports which did take a ridiculous amount of bandwidth.

There is an official PUN thread in unity forum you should post there so ppl is aware of this too. As I landed here by chance.

Are you talking about your tank bots controlled by a master client?

In my example, the bot does not transfer its rotation over the network.
I know his previous and new position and I know where he needs to turn, in the direction of the movement. Everything is simpler for me =)

There is a topic on the forum where I can show my projects?
There’s a “PUN theme” - just for answering questions and feedback about the PUN

I’ve not co-op yet working, just player controlled tanks. Your approach is interesting but my tanks might point to another target and will be better that master client computes all the bot logic and transfer rotations and RPCs of firing.

Here.

This is the photon “official” thread. Just let them know your approach. I’m pretty sure they will welcome your info.

You gave me a good idea, may be the code could have a target control method for the bots that shots an RPC with the target id and the clients controls the turret in local saving 2 rotation syncs of turret and cannon and the master client controls the fire via RPC… could work!!

In fact… I could change this for the actual code too!!! just sync the target position!

You can do the following -

One turn in the tank is calculated by turning in the direction of movement of the tank

Another turn is calculated by the transfer of the target index of the position - a turn from the direction vector of the movement, into the direction vector of the target position

As a result, both turns are not calculated over the network and only the target index is transmitted

An important point - If there is a general collection that is synchronized with the players
It is not desirable to use in collections Add, Remove - to change the size of the collection in time of active gameplay of the online gaming session.
This often leads to a desync at the point where the collection is re-assembled

List target
Let’s say the first ten items of the target collection are the players the remaining elements of the collection are bots

Select the size for the collection of targets,before calling functions OnPhotonInstantiate() from other players

Create network prefabs :

object[] objs = new object[] { index_player_tank};  // 0....9
PhotonNetwork.InstantiateSceneObject(player_tank.name, position, rotation, 0, objs); // create Network Bot prefub
object[] objs = new object[] { index_bot_tank};  // 10...100
PhotonNetwork.Instantiate(bot_tank.name, position, rotation, 0, objs); // create Network Tank prefub

Synchronization of collection initialization for all players :

void OnPhotonInstantiate() // Function is called all when created Network prefub
{
    object[] objs = photonView.instantiationData; // you get the index of the target
    int index = (int)objs[0];
    target[index]=transform;
}

In OnPhotonSerializeView(Script on the tank + add component PhotonView) you receive an index of a target of this object of the tank (the player or the bot) and you turn where it is necessary

Synchronization of the removal of the elements of the target collection
in function [PunRPC] “delete” :

int index = target.FindIndex(x => x!= null && x.transform == transform);
target[index] = null;

An important point - search by index in the collection of target.First of all, certainly check for null. Elements from the target collection are removed by player disconnect.
[PunRPC] “delete” is a reliable message in PUN and it will be lost it can only during the disconnect of the player.

1 Like

OK now I’m doing the networking code and your post is awesome, I read yesterday but was late and it has a lot of good advice. Its funny because I got mad trying to find information about instantiation data, but by the time I readed your post I was not aware what instantiation data really meant and so the syntax I could barely understand.

Now that I fully understand this is a great post.

Also instead of sync the target pos and do a sync of what transform is targeted via RPC by the AI is an AWESOME
idea to save traffic. It might require some rewrites but sure its worth.

For my game not because there are many obstaclea and I need exact position of the bot tank for all clients, but could be a good idea for a game with lesser obstacles to sync AI bots positions (paths) by simply syncing the path target and let the AI move locally. Depending on your code could make the bots take too different paths…

But for my case I’ll keep the tank body position + rotation sync. and for the AI will do the Target RPC thing. For the players I think is still better to sync a different target that is controlled by the mouse, this will save me two ration sync against 1 positio sync of the mouse target.

I think you suggest to sync a direction vector for the tank position, I’m not sure if I know how to do that so for now I will sync rot and pos XD.

Tx 4 your help!

Release :

1 Like

Cool. Atm my tank number is limited by the physics, but if I manage to add soldiers I will definitely get your package.

Less traffic is allways better so after I release my next update I will likely going to try to improve network performance with your package.