#archived-networking

1 messages ยท Page 90 of 1

silent zinc
#

that way?

#

i mean in my status packet, i'm passing the Xmove and Ymove values which are the input values and also the localPosition x, y values of the gameobject.

grim violet
#

id just send the position

silent zinc
#

Isn't a way to fix physics errors?

#

ok, but if i send the position, i'll have to trust my packet speed for that?

grim violet
#

?

silent zinc
#

Previously i was drastically assigning the position, you sayed

#

what should i do instead?

#

what's lerping?

grim violet
#

well what did you to fix it

#

moving an object from a to b in a period of time

silent zinc
#

I passed the force values instead and used the same character controller methods on the opponent

grim violet
#

smoothly

#

instead of being a, then b, then c

silent zinc
#

what if tot seconds i update the gameobject position with those values?

#

and keep moving the character with physics

grim violet
#

seem it would work too

#

but on the client, it would make alot of calculation

#

lets say you have 100 player

#

they all doing physics

#

instead of just lerping from a to b

#

depend of the game and all really

silent zinc
#

So if i take the previous x, y position from the previous packet, and update when a new status arrives, by lerping with new and previous points and delaying with 16 ms , i should get a smooth movement?

grim violet
#

i dont know how to do the math

silent zinc
#

there are utlities functions for that i think on Math

#

and Mathf

grim violet
#

yeah but calculating the lerp with packets and all its complicated stuff

fast stone
#

im sure about this error

#

its some bug

grim violet
#

id take a look at that steve

fast stone
#

idk how to fix it rly

#
{
    public bool MoveDir = false;

    public float MoveSpeed;

    public float DestroyTime;

    public float BulletDamage;


    private void Awake()
    {
        StartCoroutine("DestroyByTime");

    }


    IEnumerator DestroyByTime()
    {
        yield return new WaitForSeconds(DestroyTime);
        this.GetComponent<PhotonView>().RPC("DestroyObject", PhotonTargets.AllBuffered);
    }


    [PunRPC]
    public void ChangeDir_left()
    {
        MoveDir = true;
    }

    [PunRPC]
    public void DestroyObject()
    {
        Destroy(this.gameObject);
    }

    private void Update()
    {
        if (!MoveDir)
            transform.Translate(Vector3.right * MoveSpeed * Time.deltaTime);
        else
            transform.Translate(Vector3.left * MoveSpeed * Time.deltaTime);
    }
   



    private void OnTriggerEnter(Collider collision)
    {
        if (!photonView.isMine)
            return;

        PhotonView target = collision.gameObject.GetComponent<PhotonView>();

        if(target != null && (!target.isMine || target.isSceneView))
        {
            if(target.tag == "Player")
            {
                target.RPC("ReduceHealth", PhotonTargets.AllBuffered, BulletDamage);
            }
            this.GetComponent<PhotonView>().RPC("DestroyObject", PhotonTargets.AllBuffered);
        }
    }

}
#

there is code

grim violet
#

you dont need to observe that

subtle gale
#

@gleaming prawn do you happen to know if it will it be difficult to migrate to fusion from bolt/pun?

fast stone
#

some one can help me fix it

#

๐Ÿ˜›

grim violet
#

Kio

subtle gale
#

trying to figure out if it is worth setting up some basic networking right now with bolt or just wait a bit

grim violet
#

PhotonView - > Observed Component

#

remove your script

#

thats it

fast stone
#

ok

grim violet
#

you dont need to observe a punrpc

#

you observe OnPhotonSerializeView

fast stone
#

ye but i dont have this OnPhotonSerializeView on my bullet script

grim violet
#

exactly

#

what is your first language

fast stone
#

Pl

#

polish i mean

grim violet
#

too bad, out of my range

#

;p

fast stone
#

mostly i know what u write

#

lol

grim violet
#

hehe

fast stone
#

if i delete it from photon view i got error about OnPhotonSerializeView

grim violet
#

screenshot the component

#

PhotonView

fast stone
grim violet
#

and its still giving that error?

fast stone
#

Yes

#

but orther

grim violet
#

there must be another

fast stone
#

wait a sec

grim violet
#

another PhotonView?

fast stone
#

Yes i got it on my player

#

why ?

grim violet
#

is it observing the bullet script too

silent zinc
#
for (float i = 0; i <= 1; i += 0.2f * Time.deltaTime)
{
    gameObject.transform.localPosition = new Vector3( Mathf.Lerp( oldStatus.positionX, 
    status.positionX, i), Mathf.Lerp(oldStatus.positionY, status.positionY, i), 0);
}
``` @grim violet  i'm trying with this...+
fast stone
#

@grim violet wait no, after delete it from view

#

i dont have any error

grim violet
#

black magic

#

steve does it work

silent zinc
#

yeah?

#

i mean, seems yes

#

but still not perfect

grim violet
#

maybe you have to add deltatime in between

#

i dont know really

#

math aint my best

#

id ask on general code maybe

silent zinc
#

ok

fast stone
#

bleh i hate, thigns from tutorials

#

๐Ÿ˜„

slim ridge
#

@silent zinc sounds like you need to implement some playout delay. To get smooth motion, you need to interpolate between physics frames. To interpolate you need information about more than one frame.

it's like buffering a youtube video. Except in this case you want a buffer that's large enough to ensure smooth gameplay but small enough not to affect player decisions

#

the buffer being input or state

sly fable
#

i have an object in the scene with a photon view component but how do i make it so there is only one of them and not an instance of it per client

grim violet
#

if its in the scene people will only have 1 of them

#

if each player instantiate it once scene is loaded thought, not the same

sly fable
#

each client will have one tho from what it seems like

#

no its in the scene with a photonview component and each player has their own instance of it from what it seems like

grim violet
#

scene object are controlled by masterclient

sly fable
#

well there is code that is being repeated and i dont understand why

#

the only way for that to happen is if there were two of said object

#

when there is one player offline it works fine but when two players are instantiated on the network this code that the object uses happens twice

#

it spawns double the enemies

grim violet
#

probably a code problem then, if you look in hierarchy do you see the object twice?

sly fable
#

let me build and run real quick

#

according to the scene there is only one gamemanger object

#

which is the one im talkign about

#

but that same gamemanager only has a line repeated once GameObject gO = PhotonNetwork.Instantiate("Models/Player/Player", playerSpawns[0].transform.position, playerSpawns[0].transform.rotation); playerList.Add(gO);

#

but two players spawn, which it should do but I dont see how two players spawn unless this is running twice aka there are two gameManager objects

grim violet
#

debug.log see if it run twice

sly fable
#

and two enemies spawn instead of one, the code does everything twice

#

okay

grim violet
#

you will see the stack trace whre its coming from

sly fable
#

well i see one issue here,

grim violet
#

i wouldnt surprised its something with gamemanager being a singleton and being ghosted in the back

sly fable
#

whenever an enemy spawns i have a debug.log("enemy spawned") which that only has 1 log

#

but two enemies spawn so how is that even happening

grim violet
#

cause both client run that line

#

make sure masterclient only run it

sly fable
#

okay im using the gamemanager object to organize and store data and spawn enemies and stuff like that, should i just have something like if(!photonView.IsMasterClient) Destroy(gameObject)

#

because there is a lot of data being changed at runtime and it seems like only one player would need to keep track of it all

grim violet
#

you should use the master client to spawn and destroy object in the scene

#

that player that keep track of all is the masterclient

sly fable
#

exactly so I wouldn't even need it for the other clients right?

#

should i just destroy it?

grim violet
#

you shouldnt spawn it in first place

sly fable
#

its not spawned

grim violet
#

destroy what

sly fable
#

the gamemanager

grim violet
#

well no

#

if thats used by all client

sly fable
#

its in the scene at the start of the game with photonview

grim violet
#

i mean you dont only have spawner in there

sly fable
#

yea i have a lot of gamelogic that each client would need to referenced at runtime

grim violet
#

i dont know how you setup your game

sly fable
#

so destroying it wouldnt work actually

grim violet
#

but gamemanager clearly shouldnt have a photonview on it

sly fable
#

but its like there are seperate instances of the gamemanger

grim violet
#

unless its your spawner too

sly fable
#

its the spawner

#

it keeps track of the game nothing to do with the individual player stats

#

like starting and ending rounds and such

#

and spawning enemies

grim violet
#

well everything about the spawner should have the mention "if (im the masterclient) then.."

#

so only the master will spawn it

sly fable
#

okay il ltry that

slow monolith
#

@gleaming prawn I finally built my client reconciliation for the prediction system and it's working great, but directly after the reconciliation happens, is it normal to notice a very tiny jitter?

#

I havent built the interpolation in yet

#

I suppose the jitter is just caused by the different position being applied and rebuilt

sly fable
#

@grim violet it works but a lot of the variables arent being updated properly for the gamemanger, the masterclient is setting the variables properly but on the other clients side its not updated.

grim violet
#

you have to change the value on other client either by sending an rpc, a raiseevent, or by observing the component being changed and streaming the variables

sly fable
#

okay thanks man anything i want tracked across the network ill use a rpc

#

do i have to make a new function with an rpc or can i do it in a line? @grim violet

grim violet
#

read the doc on photonengine website about pun2

#

bit more touchy than a line

sly fable
#

alright thanks for the help

gleaming prawn
#

@slow monolith yes you need to interpolate slightly

slow monolith
#

Perfect thanks

subtle gale
#

oh photon has a discord too

#

didn't know that

slow monolith
#

@gleaming prawn I should pause the fixedupdate auto simulation while im doing my re-simulation right?

jade glacier
#

I think you might be falling into a trap in how you are thinking about time in game dev.

#

Unless you are multi-threading here (which would be a bad idea), there is no "time" passing.

slow monolith
#

Well I paused the physics auto simulation and I'm just running physics.simulate at the end of every fixed update

jade glacier
#

again, you are pausing something that isn't moving.

#

When you run your game logic or whatever, the game isn't "running" in the background

slow monolith
#

My re-simulation is done in a single Update() frame

#

multiple fixedupdates can occur during a single update frame

jade glacier
#

you can run your sim 1 million times, and to your game no time has passed. All you will be doing is making your game hang on that frame for a few minutes.

slow monolith
#

alright

jade glacier
#

Just like if you run a for loop...

#

everything else is stopped. It isn't asyncronous.

slow monolith
#
    {
       


        if (PerformSimulation == false)
        {

            Physics.Simulate(0.02f);

        }

    }```
#

So this is wrong

#

?

jade glacier
#

Your only concern is if your resim takes so long that it causes a frame rate drop, and makes your game hang.

#

Nothing wrong there

slow monolith
#

alright

jade glacier
#

But why are you disabling that simulate?

slow monolith
#

I disabled auto simulation, and I manually call simulate at the end of every fixedupdate

jade glacier
#

I think you are doing that because you think you have to "pause" things while you resim... which is the error in thinking

#

Disabling autsimulate is good, and normal yeah

#

When you rerun your simulation for whatever reason, that shouldn't be making FixedUpdate fire

slow monolith
#

Correct but

#

fixedupdate runs regardless of what update() is doing

#

so fixedupdate CAN be firing while my simulation is running

jade glacier
#

Again, you are talking as if this is asyncronous

slow monolith
#

yeah I think im confused

jade glacier
#

It cannot

#

this is single threaded

#

Fixed will not run again until you release all control

#

If you have a method that is rerunning your simulation, that all happens before Unity gets control back.

slow monolith
#
        {

            Physics.Simulate(0.02f);

        }``` So remove this if statement?
jade glacier
#

It is meaningless, if it is for what you are talking about.

slow monolith
#

alright

jade glacier
#

Fixed will not run again while you are still looping through any code

#

Make sure you understand why, this is the same trap people fall into when they try to use Coroutines and it never works like they think.

#

This is all on a single thread. Time doesn't "pass" with a game engine... time is accumulated, and caught up when control is passed to the timing mechanism (in this case FixedUpdate and Update)

#

If your resim takes 3 seconds to finish... nothing will happen and your game will freeze for 3 seconds....

#

and when Unity gets control again, it will have to run a ton of Update and FixedUpdates until it is caught up on time.

#

FixedUpdate DOES NOT happen in realtime.

slow monolith
#

Yeah I suppose that makes more sense

jade glacier
#

When Unity gets control after a screen refresh and starts a new frame, it sees how much CPU time has passed since it last rendered a frame... it then divides that by fixedDeltaTime to see how many "ticks" worth of time has passed since it last ran....

#

It then calls FixedUpdate that many times, and runs PhysX that many times.

#

THEN it calls Update()

#

Then LateUpdates.... then it renders the results to the screen...

slow monolith
#

My next question: Unity is non deterministic and my player moves with physics on both the server and client

#

however, the movements are basically the same, within a thousandth of a decimal

jade glacier
#

You will constantly be fighting with desyncs

slow monolith
#

is this only because im running on the same hardware?

#

desync isnt a problem

#

Will other hardware have more desync problems though?

jade glacier
#

Any number of things can cause desync in that environment

#

like losing a packet?

slow monolith
#

Correct

#

but I was under the impression that the physics movements would vary wildly

#

but that's not happening

#

they're fairly consistant between server/client without re-syncing them

jade glacier
#

wildly isn't the case for a lot of things. But the butterfly effect eventually will come into effect if they aren't the same deterministically

slow monolith
#

alright

jade glacier
#

that and non-deterministic actions by players

#

If two players bump into one another, a desync has to occur

#

All player actions are going to throw chaos into the system

slow monolith
#

Last question

#

if I'm re-simulating my player on clientside and say I have another object, a cube with a rigidbody falling

#

and I dont need to do resimulation on that cube, only the main player

#

Do I just set the cube to kinematic

#

then back to dynamic after the simulation?

jade glacier
#

If you aren't deterministic, that is pretty normal to only resimulate the things that need to get into closer sync.

#

Redoing the entire simulation for all objects is kind of pointless if you aren't deterministic

slow monolith
#

Correct

#

which is why im only doing it for my player

#

but will I need to re-apply the velocity to the cube after I make it dynamic again?

jade glacier
#

Typically for what you are doing, you are just trying to get the player into closer agreement than it was a moment ago.

slow monolith
#

Yeah but the problem is, physics.simulate simulates ALL objects

#

I only need it to do one

jade glacier
#

Make a separate scene

#

For my experiments and others I have heard of as well, make a scratchpad scene

#

And populate it with simple versions of your game objects from the real scene... just colliders and empty gameobjects...

#

and you enable and move those around as needed, if you are doing small isolated resims.

slow monolith
#

Won't that eat up performance?

jade glacier
#

A lot less than resumulating your entire scene just to get a players movement closer to agreement with the server.

#

There is no one answer. Depends on what your simulation consists of.

#

And what you are trying to get out of your resim.

slow monolith
#

I think 2d has an option to only simulate a specific rigidbody in a scene

#

not sure why 3d doesnt have that yet

jade glacier
#

If two players bump into each other.. you won't want to resimulate 50000 objects just to get those two into sync.

#

If this were deterministic you would have to.

#

But you are not.

slow monolith
#

ok

jade glacier
#

You might consider not using PhysX for your player controllers

slow monolith
#

Whats my other option?

jade glacier
#

If your code isn't PhysX simulation, then you can just rerun your own simulation code.

slow monolith
#

like the character controller for example?

#

custom physics?

jade glacier
#

The other option is your own more lightweight physics specific to your exact objects needs

#

a CC yes

#

That is what Bolt does, it has its own character controllers for people to use with their own simulation code, which allows for it to do quick rewinds and such.

#

Though that choice was because PhysX in Unity back then was pretty restrictive.

slow monolith
#

I was actually wondering how they did it before physics.simulate existed

#

that sounds like a lot of work

jade glacier
#

Major titles don't rely on PhysX the way hobbyists do

#

For real shooters, the game devs manhandle their player movement code

slow monolith
#

Only problem is, I need cars, and the wheel colliders only work with a rigidbody

jade glacier
#

You are limited to how much you can make PhysX bend then yeah

#

RocketLeague had to invent a bunch of their own tech for networking for a reason

slow monolith
#

Do you know if unity has plans to use physics.simulate on a single rigidbody?

jade glacier
#

I don't know of any such plans, but I don't really follow them that closely.

slow monolith
#

ok

floral turtle
jade glacier
#

That particular request might come from the MLAPI team when they try to make server authority work. So maybe it could happen?

#

It is a very specific thing to a very specific networking problem though

floral turtle
#

ah, that would be interesting

#

yeah, and you'd still need to do the cache clear workaround to make simulations similar across clients

jade glacier
#

The ability to simulate only specific objects against all static objects... is not something people ask for every day.

#

PhysX is just not made for that.

#

We are brute forcing a lot of this for Fusion... which is the only real answer. There is no elegant fix.

slow monolith
#

I just think unity has been alive for too long to have this little support for multiplayer games

#

maybe im just picky

jade glacier
#

Networked games is not in their DNA

floral turtle
jade glacier
#

Unity came from making single player games that run everywhere. That was always the focus.

slow monolith
#

Rust and tarkov are so smooth with multiplayer though

#

at least from what I've seen

#

I suppose they don't have a lot of physics going on though

slow monolith
#

I did some testing and it seems that setting other rigidbodies to kinematic while re-simulating the player works out pretty good

#

Please let me know if this is going to cause any major problems in the future

tribal zephyr
#

Hi, i'm using mirror and want to pickup or drop items within the world. What is the best way to archieve this?

weak plinth
#

Hi all this is my first attempt on multiplayer game and I know multiplayer games mostly depends on networking so what should I learn first like different networking solutions available for unity or the networking basics?

chilly lintel
#

Any one have tutorial about creating a multiplayer game? I know programming, don't have any fraid to get my hand on dirty but i'm difficulty find good way to implement multiplayer. The game doesn't matter, only want to know what is the best way..

slow monolith
#

@gleaming prawn When you're next online, can you give me a quick example on how you would interpolate the position before and after the simulation? I'm having difficulties, mainly because the position is always moving.

gleaming prawn
#

Do you have a tick system?

#

But if you just copy the Transform data from the simulation (that is recnciliated by server to the Unity Transform using a bit of Lerp this already helps)

#

This assumes you do not set data directly to Transforms

slow monolith
#

First, to make sure I'm even re-simulating correctly, directly after the resim happens, there should be a slight jitter right? Looks like it basically skipped a frame?

#

Also I'm not sure what you mean by server reconciliation, isn't reconciliation only supposed to happen on the client?

#

By tick system, do you mean the timestamps sent with every frame information? Pretty new to the terminology of all of this

gleaming prawn
#

To be able to do reconciliation you need to make your simulation tick based (ticks/frames counted) that you manage yourself

#

Because the lib you are using is NOT tick based as far as I know

#

Without a tick system, the reconciliation is complicated

slow monolith
#

I'm not using a library, I'm writing everything from the ground up

gleaming prawn
#

How do you RE-apply inputs when you receive a server snapshot?

#

when the input goes to server, it must go with a tick number (to be applied there when that time comes).

slow monolith
#

When I re-sync the client, server sends last valid input, along with the sequence number that belongs to the frame

#

client keeps all packet info

#

I think thats what you mean by ticks right

gleaming prawn
#

Then when server DATA (snapshots/state) come down, they must be flagged with a tick

#

THEN you can apply that, recover ALL inputs queded (in client) with a tick after that one, then RE-simulate those for the local player (this is the reconciliation)

slow monolith
#

Yep i'm doing that im pretty sure

gleaming prawn
#

If this is not ALIGNED to a clock, it will jitter

slow monolith
#

Ok thats the part where im confused

gleaming prawn
#

You need to have your clients to follow the server clock, etc

#

It's a lot of concepts together

#

I again suggest you watch FHolm's streams

#

He's teaching these subjects almost everyday now

#

With open source code examples on his github

slow monolith
#

Just to re-confirm, when the client receives the packet from the server, it contains the last valid position that the server has kept, along with a distinct ID mapped to it. Client goes back to this position then re-runs all client-side inputs which occurred after that point

#

I don't see how the server clock would come into play

#

Unless that's what you mean by it

#

But then I have that microjitter which sometimes occurs after the re-simulation is done. Is that just unity's non deterministic characteristics?

#

I'm fairly certain the jitter is just caused by me not interpolating properly

#

If not though, then ill go and watch the videos. I'm just not a fan of lectures, would rather be outright told what the issue is so I can google and skim through articles

rich nova
#

I'm guessing this channel does not cover WebGL deployment?

gleaming prawn
#

@slow monolith do you modify the Unity Transform directly when doing server reconciliation?

#

Normally you should use a separate buffer for the networked data, and THAT is where you perform reconciliation... Then you interpolate that to the Transform, etc

slow monolith
#

I'm not modifying any transforms for the reconciliation

#

my main character is physics based

#

so I call physics.simulate

#

unless I misunderstood your question

#

But yeah to answer your question, the physics is directly being modified during reconciliation

#

for loop () {
gameobject.velocity = stuff[i];
physics.simulate(0.02f);
}

#

I also moved it from update() to lateupdate() and like half of the jitter is gone

#

still some though, I just need to figure out how to interpolate it properly

#

Sorry for the half assed example, extremely tired and going to bed

gleaming prawn
#

You have to be modifying the transform somehow on server reconciliation

#

You need a separate storage of the vector and quaternion

#

If you did not understand the question, seems like you are modifying directly, which means you have a lot more to go

#

Again, itโ€™s a bit pointless to try to โ€œfixโ€ advanced errors on something that does not have the basics done right yet

#

I again suggest you consider watching fholm videos. Iโ€™ll refrain from commenting again, as itโ€™s not leading anywhere really

sudden scarab
grim violet
#

what is not executing, the OnConnectedToMaster? if that is you need to extend your class with MonoBehaviourPunCallbacks

#

not sure thats where you set your nickname either

#

i think it should be before not quite sure

fast stone
#

what on mirro, i need give to my friend for join to my game ?

#

bsc i can run build and game from unity and then i have multiplayer

#

but if some one else want join he cant , i send him my ip adres etc

sly fable
#

i.gameObject.GetComponent<PlayerMovement>().playerMesh.SetActive(true); i wouldnt have to specify this as a rpc if the gameObject i has a photonview on it right?

jade glacier
#

you have to use the Invoke() method. Be sure to read the manual for RPCs, you wont guess it on your own. @sly fable

misty scarab
#

For photon, can I only use PUN or use any of their photon products?

jade glacier
#

I don't understand the question @misty scarab

#

Photon is a collection of services and software

sly fable
#

@jade glacier okay, even regarding objects with a photonview?

jade glacier
#

I don't get the question sorry

misty scarab
#

Photon offers multiple services, like PUN or bolt. I'm asking if PUN is the only one that can be used with unity

bright wing
#

Does anyone know how I would add the ability for a game to have multiple rooms/scenes (like Club Penguin). I am currently using Mirror and have it working with one scene but I would like to have two rooms for a player to join and see separate people

slow monolith
#

Should I be doing my client reconciliation re-simulation in an entirely different scene?

#

I tried using physics.simulate on my main scene to rebuild the movement, and its jittering awfully

#

I tried it about 20 different ways, super lost

dense hedge
#

On the jitter, are you buffering the arriving packets?

slow monolith
#

Not sure what you mean by that

#

I'm building my own solution from the ground up with literally no prior experience

#

I even tried it without a network entirely. As an example, I just got the last 5 predicted movements from my array, went back to the first position of those 5, then just re-simulated it with physics.simulate

dense hedge
#

Not sure if it applies to the issue you're currently having, but packets don't travel along a single stable route when sent across the internet. Some will get dropped, some will arrive in the wrong order, some might even get duplicated. You might transmit them at a precise interval, but that doesn't mean they arrive at the destination still nicely, evenly spaced.

#

So normally, you'll have an array/buffer/queue on the recipient that collects several packets before removing them at your fixed timestamp rate in an evenly spaced way.

#

Not doing this is will cause jitter across a network, but if it's happening locally, there might be another issue.

slow monolith
#

Yeah as I said, I tried it even without a network

#

took the last 5 predicted movements, went to the first value, teleported my player to that position

#

and simulated them all again

#

my rigidbody stutters whenever that happens

#

I tried that like 20 different ways, still jittered whenever it happened

dense hedge
#

idk, I've never tried manually updating the physics simulation

slow monolith
#

I turned off autosim and manually called physics.simulation at the end of every fixed update

dense hedge
#

Are you collecting your input in FixedUpdate()?

slow monolith
#

update

#
        {

            RigidBody.position = (PastNetworkingStuffClass.NetworkingPlayerPosition[PastNetworkingStuffClass.NetworkingPlayerPosition.Count - 5]);

            for (int i = PastNetworkingStuffClass.NetworkingPlayerPosition.Count - 5; i < PastNetworkingStuffClass.NetworkingPlayerPosition.Count; i++)
            {

                RigidBody.velocity = PastNetworkingStuffClass.NetworkingPlayerVelocity[i] * Speed;
                Physics.Simulate(0.02f);

            }

            PerformSimulation = false;

        }```
#

This is basically what my non networking resim looks like

#

just grabs the values from the prediction array

#

thats in update()

#

the stutter is pretty awful and really noticeable

#

only happens once per PerformSimulation

misty scarab
#

Photon offers multiple services, like PUN or bolt. I'm asking if PUN is the only one that can be used with unity
@misty scarab
Can someone help me

slow monolith
#

But then joy I had another idea

#

to only re-simulate an invisible rigidbody

#

and then have my player lerp to his positoin

#

I did that by making my main character kinematic while running the re-sim on the invisible character

#

the stutter was still there

dense hedge
#

I dunno, my guess is that the problem is in this mixing and matching FixedUpdate() and Update(). You might be stepping the physics simulation too slowly or your input might not be sync'd properly when you go to re-sim, idk.

#

The "fixed" in FixedUpdate means the simulation is integrated by a fixed timestep, not that it has a tick rate of that timestep. In order to deal with a varying render framerate, the physics simulation accumulates a frametime "budget" and steps N times in a row (N = budget / dt). So depending on your framerate, you can have bursts of several FixedUpdate() calls in between Update() calls or none at all.

#

At least, that's the normal, automatic behavior.

slow monolith
#

I was under the impression that I could step the physics anywhere at any time

#

physics.simulate also does not call fixedupdate

jade glacier
#

You can call simulate whenever you want yes. I have no idea what you have going on, but if you are getting massive jitter in what you are describing, you just have a serious flaw in your resim.

#

Minor jitter can be expected, since you are in fact making small corrections. But what you are describing sounds like just a bug in your code.

slow monolith
#
        {

            RigidBody.isKinematic = true;

            for (int i = PastNetworkingStuffClass.NetworkingPlayerPosition.Count - 5; i < PastNetworkingStuffClass.NetworkingPlayerPosition.Count; i++)
            {

                Physics.Simulate(0.02f);

            }

            RigidBody.isKinematic = false;

            PerformSimulation = false;

        }```
#

This alone causes stutter

#

I removed all of the player movement/teleportation and made the player kinematic while re-simulating

dense hedge
#

Yeah, I'm not sure if that impression is correct. You want to step your physics forward by a fixed amount regardless (Unity's default is 20ms), but normally your render frame rate is larger than the physics timestep, so Unity will do a burst of several sim steps at once. The way you're doing it seems either variable or too slow.

slow monolith
#

so its something to do with stepping the physics engine

#

The major problem is that there's like 2 posts on the entire forums about physics.simulate

#

so like nobody has any clue whats right or wrong

dense hedge
#

yeah, cuz I don't think anyone goes messing around with manual simulation

slow monolith
#

Rust was made with unity, they have rigidbody cars

#

and they have perfect prediction on them

#

The only way they could do that is by stepping the physics engine manually when they need to resync

jade glacier
#

We mess with simulation all the time for networking.

slow monolith
#

^

jade glacier
#

Photon Fusion and Quantum are built around that.

#

All I can say is start VERY simple

dense hedge
#

If you say so, I wouldn't know. I figured that you'd at least want input to be sync'd at the FixedUpdate rate.

slow monolith
#

Well you have to rebuild the simulation

#

whenevr you go out of sync

jade glacier
#

And set up a lot of debugging telemetry so you can monitor what is being done to the transform.

slow monolith
#

Cant do that with fixedupdate

jade glacier
#

Export to a csv file if need be, so you can look at the data in a spreedsheet.

slow monolith
#

I tried multiple computers, and even looked at it inside scene view instead of a camera

jade glacier
#

Input is captured in Fixed @dense hedge

slow monolith
#

and the player is visibly jerking

jade glacier
#

But that is outside of the "simulation", that is just gathering what will go INTO the simulation.

#

Once it is captured, the inputs become part of the permanent history.

dense hedge
#

Yeah, I mean to have it lined up with a particular tick/frame when you need to reconcile.

jade glacier
#

Resimulation is how you resync with the server, when the server gives different state results than the client predicted.

dense hedge
#

I'm aware of the fundamentals. I just don't know how you'd control the simulation in Unity with code in Update()

jade glacier
#

You gather inputs on FixedUpdate #300 or whatever.. and feed those into the simulation to get the state for frame #300

slow monolith
#

@dense hedge The idea is to re-simulate whatever you need, in one single frame

jade glacier
#

If the client is on 307, and hears back from the server the results it got for 300... and they disagreed... the client resets the objects in question to what the server said they should have been for frame 300... and then reapplies 301, 302, 303, 304, 305, 306 and 307 inputs.

#

All of those reapplication of inputs involve calling .Simulate

dense hedge
#

yeah, I was guessing that the jitter was possible caused by a mismatch in the simulation frames and what input was used to replay after reconciling

slow monolith
#

no mismatch at all

dense hedge
#

but idk

slow monolith
#

since the second example I gave makes jitter too

jade glacier
#

If it is major, then you have a flaw somewhere

eternal quest
#

which is the best networking solution for a 2d game ...free

jade glacier
#

If it is minor, then you are just seeing the non-deterministic nature of PhysX most likely. Hard to say without a LOT of telemetry.

slow monolith
#
        {
 
            RigidBody.isKinematic = true;
 
            for (int i = PastNetworkingStuffClass.NetworkingPlayerPosition.Count - 5; i < PastNetworkingStuffClass.NetworkingPlayerPosition.Count; i++)
            {
 
                Physics.Simulate(0.02f);
 
            }
 
            RigidBody.isKinematic = false;
 
            PerformSimulation = false;
 
        }```
#

but then we have this, as I've posted before

#

no movement, no teleportation happening on the player

#

just making him kinematic, running physics simulate, then making him dynamic again

#

causes jitter whenever it's called

jade glacier
#

Why make it kinematic if you are trying to simulate?

slow monolith
#

Because I had another idea

#

to only re-simulate an invisible rigidbody

jade glacier
#

kinematic by definition means "don't simulate me"

slow monolith
#

so I can lerp my player to him

#

exactly

jade glacier
#

I am not following what you are doing at all then.

#

If your main simulation is non-kinematic... then your resim needs to be non-kinematic.

#

Otherwise there is no point in resimming.

slow monolith
#

After the re-simulation happens, if you're doing it on your main player, the player is obviously going to end up in a different spot

#

he's going to teleport

#

causing a jitter

#

so you have to lerp the position

jade glacier
#

I wouldn't touch lerping yet

slow monolith
#

but the main character keeps moving, so that's going to be hard to lerp, since you need to lerp over several frames

jade glacier
#

Avoid all interpolation when getting stuff working

#

You want to see the slideshow without anything being glossed over by questionable interpolation code.

slow monolith
#

Wel the re-sim is happening all in one frame

jade glacier
#

Disable interpolation on your RBs as well.

#

You are mixing all kinds of stuff together here.

slow monolith
#

disable interpolation only during the re-sim?

#

otherwise it will jitter.

jade glacier
#

Remove all interpolation while you work our your logic.

#

You aren't going for smooth yet, you are going for not borked.

slow monolith
#

Well it technically does work

#

it's just not smooth

jade glacier
#

You are mixing kinematic in with resim... so you are already borked. Get that sorted or you are just trying to hide your mistakes.

slow monolith
#

Kinematic was only for the second experiment I made

#

I've tried like 20 different ways

jade glacier
#

I have no way to guess which we are talking about atm, sorry.

#

Do the basics

#

Reset the objects to the server state... resimulate X steps to get back to current... monitor the telemetry to see where the results deviate from the servers results.

slow monolith
#

My experiment doesn't include a server right now

jade glacier
#

That should get you very close to in sync for most object types. You are going to have errors though.

#

I am beyond confused then

slow monolith
#

Yeah im a confusing guy

#

let me re explain

jade glacier
#

What are you resimulating if you have no server state?

slow monolith
#

So for right now, I have NO server or networking involved, just so I don't have any networking variables that could fuck up my experiment

#

let me explain

#

I save all user inputs, otherwise known as the predicted states

#

during my experiment, I grab the last FIVE in the array

jade glacier
#

You are just trying to see if you can rewind and get the same results twice?

slow monolith
#

In a sense yes, I also enabled enhanced deterministim in unity's settings

#

and it's still jittery

jade glacier
#

your inputs are not predicted states btw, that is why you are being confusing.

#

your input history is your input history. Your state history is your state history.

#

Nothing is predicted, because you have no server that is the "actual" final word.

slow monolith
#

Whenever the player moves, inside fixed update, I have it saved to an array

jade glacier
#

You are testing to see how messed up things get if you try to reset objects in PhysX and apply the same inputs.

#

The answer is that they will not be deterministic

#

Because PhysX is not stateless.

slow monolith
#

But the next problem is, how would I smoothly interpolate it

jade glacier
#

Moving objects to where they were and resetting their velocity/angvel ... will still leave the cache untouched.

#

Typically once you resim, you know the state that you just showed the gamer last Update(), and you know what they should have seen... so you will lerp in that direction. The logic involved varies based on how you want to try and make that happen.

#

But that should be cosmetic only. The tick state results are the only hard reality.

slow monolith
#

I just dont understand how I would lerp to a constantly changing value

#

eg: the player's next predicted inputs

#

obviously I cant lerp inside a single frame

jade glacier
#

Nope, you have to nudge the object toward its new target. Rather than lerping between your previous snapshot and the current snapshot... you lerp between the previous WRONG snapshot and the current snapshot.

#

Your resimulation tells you the most currently correct target

slow monolith
#

So I have to re-simulate, then revert the player back to his past position, then lerp to whatever position the re-simulation gave me?

jade glacier
#

I can't speak to that. I would never resimulate in my actual scene like that.

slow monolith
#

Would you do your re-simulation in a different scene?

#

Ive heard some people doing that

jade glacier
#

But if you are using one scene, you will want to record what you just showed the user of course.

#

Or how else would you do any kind of lerping if you no longer have any information about how things were?

#

At the AAA level you would never have one simulation trying to do all of that.

slow monolith
#

So the answer is to use a second scene, running it's own physics?

jade glacier
#

It is AN answer. There is no "THE" answer, because PhysX is just not meant for this.

#

So you are just picking the least offensive hack.

slow monolith
#

yeah

#

On this second scene, would I ONLY run the physics when I need to reconciliate?

#

to save cpu?

#

2nd question: It would be a lot easier if I didn't use a rigidbody for this, and used, for say a character controller or something?

jade glacier
#

You would enable the objects involved (leave the static scene objects always enabled).. set the RBs velocities and positions.. resimulate... then record the pos/rot/vel/angvel - that is the new resimulated tick state.

slow monolith
#

alright

jade glacier
#

That is still just a part of it, you have to sort out how you are interpolating down the line. Typically you have a target snapshot you are lerping everything toward in Update().

slow monolith
#

So on my main scene, when I need to re-sim, should I execute blocking code in update(), do the re-sim on my other scene, grab the values back, and then apply it, all in a single frame?

#

And then last question, when applying the values to my main scene, should I use rigidbody.position or rigidbody.transform.position

#

I think transform is the correct answer, just need clarification on that

jade glacier
#

You still seem to be talking about this like it is multithreaded

#

There is nothing to block

#

There cannot be any Update() or FixedUpdate() calls between when you start your code segment and when you end it. The entire game logic is linear. Until you release control, nothing is happening.

slow monolith
#

That's what I mean though, to call my other scene and wait for his response after he complete's the simulation

#

would all be done in one frame

#

right?

floral turtle
#

FixedUpdate might repeat before moving on to Update, if the physics timestep is very high compared to the framerate, but it's still sequential

slow monolith
#

Sooo to answer my question

#

yes, all happens in one update frame

#

?

#

I'm being annoying as fuck, I just want to make sure I'm doing this the right way before I dedicate another 20 hours to building this lmao

#

Also do both scenes run at the same time?

dense hedge
# floral turtle FixedUpdate might repeat before moving on to Update, if the physics timestep is ...

It's the other way around. The physics simulation usually steps several times because it runs too slow to be 1:1 with the rendered framerate.
It's like this (this isn't actual unity code)

budget += Time.deltaTime;
while (budget >= Time.fixedDeltaTime) {
    previous_state = state;
    budget -= Time.fixedDeltaTime;
    physics.step(state, Time.fixedDeltaTime);
}

render_state = lerp(previous_state, state, budget/Time.fixedDeltaTime);
gfx.render(render_state);
floral turtle
slow monolith
#

@jade glacier This what you were talking about?

jade glacier
#

For a second scene yes

dense hedge
#

@floral turtle Actually, sorry. I think you had it right. It's late and I'm confusing myself. It's not just render time. The simulation will step several times if it has enough of a budget, which would imply that everything else is take a bit long.

slow monolith
#

ok

slow monolith
#

@jade glacier So are both of these scenes running physics at the same time? Or do I have to shut down one scene

jade glacier
#

I'm not sure how else to explain how there is no "same time"

#

Neither scene is doing anything until you tell it to .Simulate

slow monolith
#

but I can call physics.simulate at the same time, and theyll both respond to it

jade glacier
#

physics.simulate is just the primary scene

#

MyOtherScene.Simulate is how you simulate secondary scenes

slow monolith
#

alright

#

makes sense now

slow monolith
#

Is it normal to be seeing both scenes when running the game in the editor

#

and can I make it only see one?

jade glacier
#

There shouldn't be anything to see in your simulation secondary scene.

#

If you go that route, you will want to write a way that replicates only the colliders and key components of objects

sly fable
#

how would you hide certain ui from one player but not all?

#

I have a namtag above my player but Id like it so the player cant see their own nametag only everyone elses

jade glacier
#

which library?

sly fable
#

photon

jade glacier
#

if (photonView.IsMine) HideWhateverThePlayerShouldntSeeOfThemselves()

#

Be sure to do the basics tutorial, it covers this specific case I think.

sly fable
#

@jade glacier the ui is on a character with a photonview

#

if i disable the ui it would disable it for everyplayer right?

jade glacier
#

Not if I am understanding your question

#

Nothing is implicitly synced.

#

Do you have code that disables the UI?

sly fable
#

Ill try it out, but i assumed since the UI element I want hidden is a child of an object with a photonview it would disable it on all screens

jade glacier
#

Still not sure what you are asking. But if the object has a PV on the root, just get that PV's IsMine to determine if the child is enabled or not.

#

Be sure to do the getting started tutorial. It sounds like you are making some assumptions about networking.

austere kiln
#

Hello, So I'm trying to use "Google Play Plugin for Unity" to authenticate my game with Play Store. On my mobile, it shows me the banner of Google Play, it shows my name and level, and then returns we with Cancelled. Why is this happening? I've checked quite a few articles regarding this issue, can't seem to find a fix.

weak plinth
#

any suggestions of tutorial or blog to learn mobile multiplayer networking in unity?

austere bronze
#

Dose anyone know how to connect with unity mirror to a game?

spring crane
#

Do the samples not do that out of the box?

austere bronze
spring crane
#

Yes

austere bronze
#

oh

#

They don't.

#

You have to put a ip address in the Input field and Join the game

#

but I don't know what ip to put to connect with my firends

#

I have the game and I tested it with local host

#

but I can't play with my friends that are not on my wifi

spring crane
#

As a host you would give them your public IP and make sure your port is open

austere bronze
#

How do you leave your port open

spring crane
#

Look up port forwarding

austere bronze
#

k

spring crane
#

You can figure out this part of the process by setting up a Minecraft server ๐Ÿ˜„

austere bronze
#

lol yea

austere bronze
#

@spring crane
I have another question. I'm following this video https://www.youtube.com/watch?v=X75GbRaGzu8 and its saying that my ip starts with 192.168.1. and I can't find a ip in my config that starts with that

Want to host your own Minecraft server, but you're confused with how to port forward? Don't worry, it's super easy. This video shows you how to allow the server through your Firewall AND port forwarding! This means that after watching this tutorial, you'll have everything done and ready!

Using an extender, or more than 1 router between you and ...

โ–ถ Play video
#

my Ipv4 address starts with 10.0

spring crane
#

That can work too. The objective is to access your router's settings

slow monolith
#

Has anyone had any luck getting physics.simulate to work properly for client reconciliation?

#

Or do I need to do that in a different scene?

#

I get tons of jitter whenever I use physics.simulate inside my main scene

earnest leaf
#

Anybody has the experience of using google services? I have a question...

spare locust
#

I have a C# server and want to connect to a website using WebGl for multiplayer use. Would the Server work for multiplayer in WebGL build?

glass compass
#

Does anyone know of any way to use socket.io in Unity? I'm trying to find a way to connect Unity to my Socket.IO server.

spring crane
#

@thorn hornet You might get away with these if you don't take half a chat to do it. These sort of things are generally posted on collab sections, and we don't have one.

#

@spare locust Hosting from a WebGL build is generally a problem, but you certainly can connect to a server as you can see from most networking solutions supporting WebGL builds. WebSocket is the most common way to do it.

patent fog
#

Did you find an answer to your question ? I used only the JavaScript SDK and there you can easily access children through their path (root/child/child). There should also be a verbose way, smthg like FirebaseReference.getChildWithKey("subObject") or close, you get the idea. Check the doc ?

#

If you only want to list their name, just point the Reference to the "root"/"parent" and you should be able to iterate. From memory there should be a smthg similar to a .value() to first reinterpret the DataSnapshot as a list or anything else iterable.

vast grail
#

what networking would you guys recommend to learn first? should I learn the built in or a different one?

glass compass
#

@vast grail Depends on what will work best for your project.

vast grail
#

I am thinking of doing simple 2d arcade thing just so I can learn how networking works

glass compass
#

Learning Mirror is a solid starting place to learn the basics of networking in Unity.

vast grail
#

ok, thanks

graceful harness
#

Hey, so I have a bit of a roadblock rn. I have an object with a networkidentity and all that, and this object has children with scripts attached to them. How do I syncronise variables in these scripts across clients, if I can only have a network identity on the parent object?

#

this is in mirror

grim violet
#

the way i read it from the doc, you must spawn a prefab of your gameobject with networkserver.spawn

#

so they gonna have the whole prefab networked with 1 identity

#

there a mirror discord server i think where you could get more help about it

graceful harness
#

oh ok, thanks, ill check out there, and also try that

patent fog
#

Try 'com.unity.networking' ?

dawn forge
#

I'm at a loss at what 3rd party networking solution I should be using. Any recommendations? MLAPI does not look ready.

The critical factors I need is: cheat prevention, scalable, and doesn't require advanced networking experience to implement.

dawn forge
#

Any thoughts on Mirror vs PUN2?

spring crane
#

The primary difference I would consider is the PUN2's peer to peer over relay setup vs Mirror's more traditional client - server setup.

frank quiver
#

I think Mirror is more secure compare to PUN2

#

but depending on how you implement it...

grim violet
#

what kind of game you making

dawn forge
#

I'm making a VR game that's real time. Up to about 8 players per match is probably what I'm aiming for. Players need to see each other move around, their hand position, grabbing & moving objects.

grim violet
#

most anti cheat solution require a server with authority, which mean advanced networking experience

#

there is always way to do it with p2p and all but it get complicate quick

#

p2p and cloud scale better than having ur own server thought, which you will need to make loadbalancing and all between your own server

dawn forge
#

Is p2p and peer to peer over relay that @spring crane mentioned the same(ish) thing?

grim violet
#

yes

#

but do you need a remote server

#

can it be local

#

do you need to save stuff online?

dawn forge
#

Yeah I need to save stuff online

#

Sounds like client/server is what I need, and that Mirror is more robust at that, based on what you're saying

grim violet
#

but mirror is client server on same computer (at least i think)

#

youll need another server online to save stuff of peoples

spring crane
#

The server can be anywhere

grim violet
#

with mirror?

spring crane
#

Yes. If you couldn't move it, it would basically be peer to peer with extra steps ๐Ÿ˜„

#

It can run in Server, host or client mode

grim violet
#

i thought it was server on the same as client

#

you need to run the unity game in order to have the server up?

spring crane
#

Well you generally program it as part of the same application

#

Yes

grim violet
#

yeah i just cant stick in my head having to run a game on a windows server to have my server up

#

lol

dawn forge
#

I found a comparison chart with PUN2 and Mirror on it. Not sure when it was last updated.
https://docs.google.com/spreadsheets/d/100vNy3grUgLV5M7rIUKUtRqO4cmTewQI8P5uwf-Qb9k/edit#gid=1672881265

#

Sounds a lot like Mirror is the way to go based on what you guys are saying.

grim violet
#

i dont know mirror cant talk for it

#

i just say what ive read

#

i prefer photon

spring crane
#

@grim violet It's headless, so it doesn't feel that bad ๐Ÿ˜„

dawn forge
#

Population One (VR battle royale) apparently used Mirror, so thats a good sign. They needed scale, anti cheat, etc.

#

Thanks for help guys ๐Ÿ‘ Gonna just get started on Mirror and see what happens.

grim violet
#

on that doc list its wrote p2p in pun2 not supported

#

something seem wrong

spring crane
#

Probably referring to ability to connect 2 clients directly to each other

grim violet
#

ahh

lyric herald
#

Hey I am using Pun2 . When I disconnect from a Room and after that join a Room three PlayerManagers are Instantiated. Can somebody help me immediately or have I to post my code?

grim violet
#

i dont think its related to pun but more about your class script being a singleton

#

show code

lyric herald
grim violet
#

to prevent multiple instance to run

lyric herald
#

thank you. I think it's fixed

lyric herald
#

Now the problem is that for the other Player no PlayerManager is instantiated because the singelton script makes that only one PlayerManager can exist

grim violet
#

then dont make it a singleton

#

there can only be one

spring crane
#

Your PlayerManager should probably be able to handle more than one player

spring crane
#

Depends on what you are managing. The gist is to write logic that works with multiple instances

#

If you need to spawn players, spawn multiple. If you need attach data/state to each player, create a dictionary that maps data to each instance

#

If you need to do decisions based on a player, loop through all players.
If all logic is based on handling a collection of players, you can throw in as many players as you wish

dawn forge
gleaming prawn
#

It is a full reimplementation

#

It does not depend on old unet

dawn forge
#

๐Ÿ‘

dawn forge
spring crane
#

NormCore doesn't seem to be trying to solve a lot more than Mirror, though it probably does have the benefit of having full time employees.

gleaming prawn
#

Normcore is more a competitor to pun2

#

Not really even close to fusion, bolt, and totally different than mirror and mlapi

#

Itโ€™s relay based

grim violet
#

pricing of normcore seem half photon too

spring crane
#

Oh should have noticed. Was enticed by what appears to be physics rolling back gif on the site and walked out disappointed by the physics documentation ๐Ÿ˜„

grim violet
#

unlimited ccu 49$ a month

#

that make me so mad right now

#

lol

spring crane
#

How about the room hours stuff?

grim violet
#

i dont know what that is

#

but there is unlimited rooms up of that

#

it cant be 1000 hours in a room...

#

and no info on the website anywhere or google

#

seem like a trap

spring crane
#

No gimmicks.

grim violet
#

roll eyes

#

;p

#

never seen a company says directly we rip people

#

hehe

#

yeah thats the only bad looking thing right now

slim ridge
#

they claim to be the best available

grim violet
#

im gonna mail em and ask what it is

slim ridge
#

but dont provide any sort of benchmark

grim violet
#

cant even find an email address

#

i guess that solve it

#

oh found it

#

ill show anwser once i get it

#

or if i get it

gleaming prawn
#

They seem like a legit company, been around for a few years I think

#

Read through everything, try it out

#

(I work for photon btw)

grim violet
#

if i buy the 100 photon ccu for a year and the year end

#

im i obliged to get the 500 ccu

gleaming prawn
#

I donโ€™t think so

grim violet
#

it says one time

#

for the 100 ccu

gleaming prawn
#

You can renew for one more year and so on

grim violet
#

thanks god

gleaming prawn
#

What it says there is: pay one time, 100ccu for 12 months

grim violet
#

yeah but before it was one time for 100 ccu for 5 year

gleaming prawn
#

Yes, that was Themis deal

grim violet
#

i thoguht it was a deal, which would make this a deal too

gleaming prawn
#

The old*

grim violet
#

that confused me

#

discord lagging bad

#

or me

gleaming prawn
#

But you can renew it

#

In practice what happens is your game either works (and you go for higher tiers) or it dies in a way that you could just use 20 free to leave it around

#

Very very seldom the 5 year 100 ccu was well used

grim violet
#

i was just scared that id have to jump from a 95 a year to a 95 a month after a year, was like my game better be a success lol

#

but this is perfectly fine if i can renew

gleaming prawn
#

You only need grating the game@indeed gets more ccu

spring crane
#

You probably know after a year? ๐Ÿ˜„

grim violet
#

ahhh we never know ๐Ÿ˜›

gleaming prawn
#

Sorry for the typos, I suck at this new phone keyboard

grim violet
#

since i have no real clients etc and im not know forging a community will probably take time to reach that 100 ccu

#

thats alot of accounts

gleaming prawn
#

100ccu in practice you need around 2k DAU, around 40k MAU

#

Thatโ€™s what I see with games with real players

grim violet
#

yeah thats what i was approximatly seeing too

random crown
#

Guys i need a bit of help. So i'm trying to make a multiplayer system for my game and i'm using photon. Whenever the player is in the lobby each player is prompted to pick a role (red or blue) and once both of them picked opposite rolls they can start the game.

The thing is whenever they start the game and load into the new scene i wanted it to instantiate the players in two separate parts of the map and currently i'm having a bunch of glitches making it work.

I tried making it work by doing a for cycle that repeats twice (for both players) and that will check the player role and then with that information it will instantiate it in a different spawnpoint.

for (int i = 0; i<=1; i++)
        {
            Debug.Log(RoomManager.RM.PlayerRoles[i]);
            if (RoomManager.RM.PlayerRoles[i])
            {
                PhotonNetwork.Instantiate(playerPref.name, spawnPoints[0].transform.position, Quaternion.identity, 0);
            }
            else
            { 
                PhotonNetwork.Instantiate(playerPref.name, spawnPoints[1].transform.position, Quaternion.identity, 0);
            }
        }

The problem here is that not only does it instantiate 3 objects for the host and only the host (the cycle only runs once, but the first instantiate automatically instantiates 2 prefabs on the host side if I'm not wrong) but the camera glitches out and both players see the vision of the last instantiated player and only the first instantiated player is able to move its character.

My theory is that i have here 2 different glitches, one where it instantiates an extra prefab/photon view for the host and i'm not sure how and the 2nd its an issue with photon views instantiation and considering i haven't properly understood how you are meant to instantiate and transfer ownership of photon views the problem might lie there.

If anyone can help me i'd be extremely grateful, even if it is just to try and help pointing me in the right direction.

grim violet
#

your loop only seem to run once, if i = 0, i <= 1 mean 0 only
You have to instantiate each player on their own client after joining a room

random crown
jade glacier
#

PhotonNetwork.Instantiate by default will make the player calling it the owner of it.

#

It should instantiate on all clients

random crown
#

if i execute it once in the start function does it repeat itself for all players?

jade glacier
#

Are you trying to instantiate them all on the Master?

#

Just have each player instantate its own when they join.

#

And if you need some custom settings, you can instead have them not instantiate until they get a message from the Master telling them to, and what extra info they need.

#

That invites annoying race conditions though

random crown
#

also what is the best way to get the current player in the room? Let's say i join a room, how can i get my player from the player list of that room? Is there a specific block of code to do that like "PhotonNetwork.CurrentRoom.Players.Mine"? So far i've been doing some work arrounds bc i couldnt find the proper way to do it

jade glacier
#

So cleanest is just have them instantiate, and then have them set anything custom based on room properties, or an message from the master.

#

Let's say i join a room, how can i get my player from the player list of that room?
I am not following

#

Just get LocalPlayer if you want your local player object

#

PhotonNetwork.LocalPlayer

random crown
#

@jade glacier short version is they pick a room, they pick where they spawn, the master client starts the game and they are meant to be spawned where they picked

jade glacier
#

They need to wait for permission from the Master or something?

#

Just have them do that in OnJoinedRoom

random crown
jade glacier
#

The Player has an ID, but that may not be what you are after

#

LocalPlayer.ActorId is your unique connection ID

#

which increments by 1 as people join

#

That can get fragmented if people leave and others join

#

Master is 1, next to join is 2, next to join is 3... if 2 leaves.. next to join is still 4

random crown
#

that might be it?

#

does that id match the position in csharp PhotonNetwork.CurrentRoom.Players[ /*the id here*/ ]

jade glacier
#

that is a List no? I don't recall.

random crown
#

Dictionary i think

jade glacier
#

Then there is no "position"

#

It is, or it isn't

#

The actorId is the key though

grim violet
#

can actor id reach a max or it loop back from an empty id from beginning

random crown
#

oh shit you are right... i'm an idiot...

jade glacier
#

Not sure @grim violet

#

Not sure anyone has realistically ever found out

grim violet
#

if i have people constantly joining and leaving a room

jade glacier
#

viewID is an int right?

grim violet
#

i think so

jade glacier
#

int.maxValue > any game has ever run in Unity ๐Ÿ™‚

grim violet
#

if viewid are set at the thousand thought for player thats 2.2m numbers

#

but like im building a mmorpg which scene can be active for a very long time unless there absolutly no one in it for 5 minute

#

a scene can be a village where people come in and out anytime

jade glacier
#

the player count would be more like int.maxvalue / 1000 yeah

#

but still more than I am aware of anyone ever hitting. I would expect it to loop.

#

But I haven't looked, because why ๐Ÿ™‚

grim violet
#

im really talking to the extreme but if scene is on for a month and people join alot and leave alot in a day that number can get high quick lol

jade glacier
#

Pun2 is not meant for that kind of game, nothing about it is geared toward persistent anything.

grim violet
#

why not o_O

jade glacier
#

From the ground up it is designed for small player count rooms with a finite existence.

grim violet
#

can the room eventually crash

jade glacier
#

I would hope not, but eventually Unity would just crash.

#

Time.timeDelta alone will start to break things after too much time.

grim violet
#

so far its working well

#

been online in some room for days

#

but yeah dint try with a big amount of people

#

just me myself and i

jade glacier
#

The code is all right there, you can look at the method for getting a viewID and see if it loops around

rigid raven
#

I'm working on a multiplayer brawl game and i want to get latency as low as possible. I'm considering the option of p2p to cut latency in half. My package size including header is less than 100 bytes and i'm sending at 30pps. Could it cause issues to have 100+ players inter-connected in a p2p network? Can a router handle it?

#

I'm using LiteNetLib

stiff ridge
#

@grim violet, PUN will not work with hundreds of players and endless games. It is not built to scale in this way. Small groups. Short-ish running rooms.

#

It is lacking some features to enable more users and networked objects. You can push the boundaries for sure but .. we won't really put work into support for it.
Long running rooms work against the way we do loadbalancing across machines. So .. you should run your own servers for something long running (which gives options to save state, etc).

grim violet
#

im using webhook to save the persisting data

stiff ridge
grim violet
#

extreme case in a room would be max 50 people, beside the movement of character and animation trigger there nothing im checking on character in general

#

its a turn based i just want peoplke to walk around and see each other

#

so far its working super fine

#

there will be plenty of room too, people will move around

#

sometime rooms will close by themself cause of lack of people

rigid raven
#

3000 packages at 100 bytes each, is 300kb of data being sent each second

#

doesnt sound like a big deal to me, but i could be missing something

stiff ridge
grim violet
#

yeah im reducing everything to the bottom lol

#

or i try to

#

i got map with ressources people can collect, i use custom room properties to hold values while there is people but they get it from my server

#

they get just once thought, again to minimize data receveid and sent

stiff ridge
rigid raven
#

in this case, the client would receive 30pps back from 100 separate connections

stiff ridge
#

Oh, you don't mean "listen server" but real p2p. Then, no, I can not imagine this working properly.

alpine pivot
#

100 people connected p2p? Dude that's crazy

dense hedge
#

The bandwidth might be doable but those packets won't arrive with nice pacing.

Any stream of packets sent over the Internet can be rearranged, staggered in weird ways, or have duplicates inserted by some router along the way.

If packets from 2 players (let alone 99) for a single frame arrive a bit skewed, you'd potentially have to rollback that frame multiple times. Is your game loop fast enough to do that?

jade glacier
#

P2P is a term that is misused in networking, so best to always be specific about what you mean.

#

True p2p is every client directly connecting to every other client. Which is practically unheard of in game networking.

dense hedge
#

It's not unheard of. How do you think fighting games have netplay? But you are right in that, if you have one client hosting, it'd probably be doable.

jade glacier
#

Practically unheard of

dense hedge
#

close enough, I guess

jade glacier
#

Two player games don't count, since there is no distinction until you have 3+

#

Two players with one hosting will either be client listen or a lockstep

dense hedge
#

Yeah. Would you see a true P2P in a "LAN mode"?

jade glacier
#

Add a third to those and that is where things get messy.

#

Even lan modes typically have an authority

#

Unless it's doing a lockstep or something

dense hedge
#

p2p would have to be lockstep, wouldn't it?

jade glacier
#

Not sure what all the architecture options are. I have never made a true p2p.

#

Probably never will. Too messy.

dense hedge
#

tbh it seems limited in usefulness: 1v1 games built on GGPO or something like it

gleaming prawn
#

even in 1997 there were predict/rollback determinsitic games with a central host coordinating input

#

So pure P2P is just a bad approach IMHO

jade glacier
#

People always want to try it

gleaming prawn
#

Ye, people always want to build MMOs as well

jade glacier
#

Thinking they will get some miracle result

#

Erick knows way more than me about this topic btw

dense hedge
#

I guess the limit with designating a client as the authority is that you couldn't guarantee that client has the network bandwidth (or cycles) to support 100 players.

#

Especially since the client also has to render its own view.

jade glacier
#

There is a long list of problems it creates.

dense hedge
#

#1 is probably cheating

#

So in client-server and client-host games, how do you ensure clients are predicting ahead just the right amount so their input is highly likely to reach the authority on time but not too early?

#

Do you just measure ping/jitter and try to maintain whatever lead keeps you at a certain % packet loss?

jade glacier
#

Prediction just means that objects owner by players simulate immediately. They exist on the future, but are not confirmed yet.

dense hedge
#

that wasn't the question

jade glacier
#

You mean how do you manage the server buffer sizes?

dense hedge
#

No, like, clients will need to predict ahead by a variable amount based on their RTT to the authority.

#

I guess it's like the reverse of server buffer size?

jade glacier
#

They don't do that though, they just simulate immediately

dense hedge
#

No, you will. A client has to simulate frame N at least half their RTT ahead of the server doing it.

jade glacier
#

We must be talking about different things

dense hedge
#

I think so

jade glacier
#

Player prediction refers to letting the client simulate their own objects immediately.

unkempt beacon
#

is it possible to setup a server/database for my game on my computer? If so is there a free/cheap way of doing it?

jade glacier
#

Are you talking more about lag compensating or extrapolating? @dense hedge

gleaming prawn
#

@dense hedge is correc

#

correct

#

No matter if deterministic or not, you'll be ahead of server with your prediction

#

I mean, ahead of confirmed data

#

In quantum, it's normally around RTT/2

#

in state transfer, it's normally full RTT

#

Sorry, but I'm a bit busy to explain why atm

jade glacier
#

His question seems more like how the right buffer size is maintained by the server. If that is the question, that varies. For Fusion clients get constant buffer size feedback from the server, and slightly adjust their sim rate as needed to keep the buffer within spec.

#

But clients aren't guessing ahead by x milliseconds... They are just simulating on a fixed tick, and sending their inputs for that tick to the server.

#

If we are talking about predicting your own player objects locally... vs predicting unowned objects.

#

And my answer is related to state transfer with server authority. Answer likely is different for any kind of lockstep.

dense hedge
# jade glacier His question seems more like how the right buffer size is maintained by the serv...

I do think my question basically has the same answer as "How do you size the buffer? A constant buffer wouldn't be optimal for someone whose ping goes from 200ms to 50ms or vice-versa.

However, because the server can only buffer a particular input packet until it's time to use it, the client is responsible for adjusting when those packets arrive by adjusting how far in advance it simulates/predicts and sends input.

So conceptually, "time spent in the buffer" becomes "how much to predict ahead," but the value should be the same.

If you had a bird's eye view of all clients at the same time, they should all be simulating a different tick locally.

jade glacier
#

There are a couple buffers in play of course as well.

#

If you are trying to server the buffer of inputs on the server... you size that by asking clients to speed up or slow down.

dense hedge
#

Is that speeding up / slowing down done by dialating the local timestep? I.e. instead of 16ms, the client pretends it's 15ms.

jade glacier
#

If you are talking about the state buffers coming from the server going to clients, they can have any number of mechanisms for correcting - but typically involve changing their tick offset in relation to the server ticks.

#

yup

#

That is the Overwatch method and we use that for Fusion

dense hedge
#

Right, so I'm more just wondering about particulars of the feedback system that tries to keep the "buffer" as small as it needs to be.

jade glacier
#

That is subjective. I wrote that segment for Fusion, so I have my way of doing it.

dense hedge
#

I see. I was reading a bunch of papers about playout delay for VoIP and they do have a variety of methods.

grim violet
#

what is fusion

jade glacier
#

New Photon networking library that is in Alpha

#

The future replacement for Bolt and Pun

dense hedge
#

@jade glacier thanks for all the clarification

restive orbit
#

If anybody could help me out with this I would really appreciate it (working on a online FPS that started out as Local only):

Right now, I am using for each player 2 layers to render the world: the first layer for all the FPS components of a certain player (ex Player1_FPS) and the second layer for all the 3rd person components (ex Player1_3PS) and I do that for the other 3 players: Player2_FPS and Player2_3PF, Player3_FPS, etc This is so the player can see the other player's third person character but not the first person arms. I tired only having 1 Layer for FPS components and 1 layer for third person components but oviously you are then able to see your character's 3rd person body and the other player's 1st person arms.

You do the math and that makes 8 dedicated layers total for 4 players. As I am thinking about making an online mode I came to realise I will run out of layers really fast concidering Unity only allows 32 layers (16 players max) with a few already dedicated for the engine.

I think I am completly missing something, but I am struggling finding information on this.

Any help would be awesome.

patent fog
#

Cant you work with the islocalPlayer (not the actual name) bool instead of layers ? And disable rendering or not spawn at all based on that ?

restive orbit
patent fog
#

Great, happy coding !

cosmic hinge
#

Hello all, i dont quite know where to put this but i just set up a project using OVR (VR) and Photon 2, I set the basics up it worked for a sec and then i start having problems with the editor crashing on play. If anyone knows how to read editor logs may you check to see if it is photon related ?

stiff ridge
#

I don't see any pointers to problems with PUN. It's also not known to crash Unity, so it's more likely something else.

wanton scroll
#

hey people I have a really dumb question I'm just not experienced with web stuff. If I'm using UnityWebRequest do to a POST to a https link am I automatically secured with SSL? I mean the POST does not go in plain text form right? I'm also using a WWWForm for the data itself.

silent flame
#

Which technology is best for making a game like club penguin mmo? I heard they used smartfoxservers but photon seems more intertwined with unity and the more popular choice. Also I've heard photon isn't good for mmo's

fading chasm
#

hey all, i'm using PUN 2 in my project, and following some tutorials to try to import photon 2 Voice as well. none of the tutorials thus far have described what to do when you import photon 2 Voice and the package looks to want to overwrite 90% of your existing PUN 2 library. anyone know if you're supposed to go ahead and overwrite?

#

also @silent flame curious if you heard any specific reasons about photon not being good for MMOs -- and which alternatives might be better

silent flame
#

@fading chasm not a specific reason. I heard that they are good for games <32 people and they are working on being better for larger people games. This was all in those "don't make an mmo" posts so maybe the answers were just trying to be discouraging to the posters.

#

I am not experienced with multiplayer dev yet so I was trying to find the right technology for my game. Sadly most posts suggestions are "dont build mmo" but I am not trying to do anything commercial anyways just wanting to learn ๐Ÿ˜„

white stone
#

Look at the network plugins based on popularity on the asset store then look at the reviews and read the reviews to get some sort of idea https://assetstore.unity.com/tools/network it's important you read the reviews. Use the Sort By to work it out. Also if they've support whether it's Unity Forums or there own forums, go and read them. Tons of support out there.

silent flame
#

will take a look rightaway. thank you

fading chasm
#

thanks for the help!

verbal lodge
silent flame
#

Awesome. Looking at these now also. Thanks a ton!

white stone
#

Not a lot of people will share there results on what they use, some people just keep it to themselves and will rarely share the answers because it's just to much of a massive playing field to give the right answer, sure PUN might be useful to the person running 48 players or 12 players but remember if someone says something isn't good for MMO that is because that is based on there experience, not yours, don't let it get you down. There answer is there, you just need to explore all avenues.

silent flame
#

That makes sense ๐Ÿ™‚ thanks!

white stone
#

I would love to say use BLAH but I don't know anything about your project, the ins and outs of it and everything in between, what I can do like a lot of others like @verbal lodge is provide links to resources which will help you learn a little more and push you in the right direction so one day someone else will be on here asking the same question and you'll be here and you'll be able to answer because you know exactly how you felt when you asked.

stiff ridge
stiff ridge
#

It helps you realize the problems you run into when you sync games and when you add more and more players. This is nothing the "right" engine will solve, when you talk about MMOs. Pretty much all networking solutions only solve problems for < 32 players. Maybe 50 or so. Anything above that will require some more knowledge, which can not be explained in a few lines of chat.

fading chasm
#

Thanks @stiff ridge!

silent flame
#

Thanks so much @stiff ridge and @white stone both were really insightful. I will try to dive into mirror and see what i can learn out of that

slow monolith
#

How non deterministic is physx? Should I be expecting wildly different positions on different devices?

#

or should they be somewhat the same?

gleaming prawn
#

They will drift

#

And over time butterfly effect plays itโ€™s role and things get totally different

#

Itโ€™s not wildly different on the first seconds

muted garden
#

This is a picture of another person
this is not showing up for me for mirror
but for other things like Unity.engine and system it is working

slow monolith
#

So the newer releases of unity have "enhanced determinism" as a setting

#

how bad is the performance scaling with this?

slim ridge
#

i wouldnt buy into it

#

cause i dont know what "inserting actors" means.

slow monolith
#

Can someone explain how I would to the lerping on the clientside after the clientside reconciliation is finished?

#

like I've got the old position, and the new re-simulated position

#

I just can't figure out how to do this smoothly

#

My other option is to just not lerp at all, but then the player jumps and it's somewhat noticeable

high night
#

@slow monolith you keep the last two position-time pairs sent from server
and use them to interpolate depending on the current time

#

https://gafferongames.com/post/snapshot_interpolation/
This should talk about that in more detail

slow monolith
#

@high night Having an awful time trying to wrap my head around this. The positions are interpolated over several frames, but what happens if the client moves during that interpolation?

high night
#

do you currently have predictions going on currently with this scenario?

slow monolith
#

Yes

#

player is physics based

#

and is predicted

high night
#

then this is not about that article or what i said

#

you are asking how to do the rubberbanding smooth?

#

the times when client predicts the character wrongly i mean

#

@slow monolith

slow monolith
#

Yes

#

exactly

high night
#

lets say you have your characters physics and logic seperated from the visuals

for physics body, you should instantly replace it to its new correct position
and the visual one should always follow the physics one via something like snapshot interpolation

slow monolith
#

So technically my camera shouldn't be on the rigidbody? It should be on something following the rigidbody?

#

and make the real rigidbody invisible?

high night
#

if the camera is going to be smooth, it cant directly be on the rigidbody, or directly following the rigidbody

#

Yes, i'd make the real logical character invisible

#

And when you shoot a bullet, you shoot it from rb, not the camera

slow monolith
#

alright

#

wym by the camera can't be directly following the rigidbody?

#

was that a typo?

#

What I meant is, have another gameobject lerp to the rigidbody

#

whenever it moves

high night
#

I am talking about making another gameobject following the rigidbody

#

and thats the visual model of the character

#

and camera

slow monolith
#

that makes sense

#

do I lerp or smoothdamp

high night
#

lerp wont be super smooth

#

you'd have to do that little more complicated lerp i was talking about

slow monolith
#

yeah I would have no clue how to even start on that

high night
#

if you tried to lerp like you are thinking right now, you'd notice some issues with it as speed gets a little higher

slow monolith
#

yeah

#

isn't smoothdamp a fix for that though?

#

pretty sure you can cap smoothdamp speed too

high night
#

the thing is

#

you need to lerp like this:
interval = (time - prevTime) / (nextTime - prevTime)
lerp(somePrevValue, nextValue, interval)

instead of:
lerp(currentValue, nextValue, constantNumber)

@slow monolith

#

To keep the lerp consistant

slow monolith
#

yeah I think the docs have something similar

#

if I'm not mistaken

#

just never played with it before

high night
#

Mathf.Lerp or Vector3.Lerp already has what it needs

#

You just dont wanna plug the current value in there

slow monolith
#

Perfect, thanks for the help

high night
#

You understand what i mean by all that?

slow monolith
#

Yep, I get it now

#

the only issue I had was the stutter, and that should fix it

high night
#

Okay then

#

Good luck

#

@slow monolith Why do you have these prediction errors anyways?

#

You shouldn't have much of them predicting the local player?

slow monolith
#

Both server and client uses rigidbody to move the player

#

so naturally as erick stated, they'll start to drift apart

#

If I used character controller to move them, there would probably be a lot less

#

until packet loss hits

high night
#

if these drifts are too noticable, maybe there are some things you can do to improve the determinism

#

Or maybe you aren't syncing velocity or something when you adjust the rigidbody into its previous state

slow monolith
#

nah I'm syncing everything fine, it's just during my tests I purposely reconciliate on every packet received

#

just so test it

#

your previous solution should work just fine

high night
#

allright

slow monolith
#

I also tested only teleporting the player to the new re-simulated position with no lerp, and the teleport was extremely tiny

#

but noticeable

#

cant move on until its perfect

#

@high night Last thing. So when I build my cars and have a first person cockpit view, I would have an invisible car-sized rigidbody, then the actual car model would be lerping to that rigidbody's position?

high night
#

yes

slow monolith
#

Thanks

high night
#

player and car and camera following the rb the same way

slow monolith
#

How would I do the wheel colliders? Just make the wheel rotation follow the invisible rigidbody's wheel colliders?

#

Also the visual model shouldn't have any colliders on it, right?

high night
#

i'd make a nice system to sync objects with that lerpy buffery technique
it would do that lerp for position and rotation

I'd make the car body model follow the rigidbody car body
and wheel models should follow the real invisible wheels the same way

#

@slow monolith no colliders/rbs on visual models

slow monolith
#

Alright thanks

slow monolith
#

Also how do I make sure the rigidbody and the visual gameobject don't get too far apart?

#

is that in the lerp function you gave me?

#

@high night

#

Also how many games have you used this method in?

high night
#

I dont have a good solution with dealing with that falling apart problem

#

@slow monolith I never really got to use this anywhere yet, always had simple lerps as placeholders that i didnt get to upgrade

#

You could try extrapolation but you'd lose the perfect sync

#

Like if the car is taking a turn and you extrapolate the visuals, the turn radius will be higher than the rigidbodys turn radius

#

Maybe extrapolation wont be too big of a deal

#

You'd just have to add some extra time on the lerp interval
So that it always matches the client time

#

That time would be proportional to client latency

slow monolith
#

alright

#

@gleaming prawn Sorry to bother you again, but you're the multiplayer god, is this ^ how you would do your clientside interpolation process?