PhotonNetwork.Instantiate teleports objects for other clients
Options
Merry Christmas!
Wondering how I can improve this issue. My master client is ok with instantiating new objects into the game, however, the other players see it teleporting/flying to it's spawn location.
How would I fix this?
This is done on the master client.
GameObject asteroid = (GameObject)PhotonNetwork.Instantiate(someasteroid, spawnSpots.transform.position, spawnSpots.transform.rotation, 0);
Wondering how I can improve this issue. My master client is ok with instantiating new objects into the game, however, the other players see it teleporting/flying to it's spawn location.
How would I fix this?
This is done on the master client.
GameObject asteroid = (GameObject)PhotonNetwork.Instantiate(someasteroid, spawnSpots.transform.position, spawnSpots.transform.rotation, 0);
0
Comments
-
Do you use an RPC for moving the asteroids or do you use send the position and rotation information over the network in OnPhotonSerializeView() ? Maybe you have forgotten to observe the script in the photonView?
Some more infos needed Could have many issues.0 -
Asteroids have a networkscript "OnPhotonSerialize" and I am also observing the script in PhotonView.
Also observing the rigidbody2D in PhotonView.0 -
Please show me the code of how you sync the objects
Here is what i use for update a position (don't forget to start the coroutine):Vector3 position; IEnumerator UpdateData() // start the coroutine in void Start { while (true) // endless loop { transform.position = Vector3.Lerp(transform.position, position, Time.deltaTime * 10); yield return null; } } void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) // you NEED to name it like this { if (stream.isWriting) // sending { stream.SendNext(transform.position); } else // reading { position = (Vector3)stream.ReceiveNext(); } }
Compare this with your script.
You don't need to observe the rigidbody if you don't change the properties and if so, you should use rpcs for this anyway
What i don't get is that you spawn the asteroids at a spawn location and you see them flying through it?
So where are they spawning or what do you want to do with the asteroids? Are they spawning at vector3.zero , at the spawn points or at another place and you see them flying through the spawn points.
Greets
0 -
That's real similar to my code. I also included rotation though.
So my asteroids have a spawn point, but they spawn at Vector3.zero for other clients.
On masterclient, they spawn at the appropriate locations.0 -
So they spawn/photonnetwork.instantiate at Vector3.zero for other clients and then "fly" to the proper spawn location.0
-
Ah yeah now i got you. There is no problem with your sync etc. that's all fine. Try this code:
Make a private bool and call it bool initialLoad and set it to true than use this code (you can use this with the code from above)://...On first load we don't want to let the asteroid "fly to his correct position" if (initialLoad) { initialLoad = false; transform.position = position; }
This should fix the error0 -
0
-
@Pav Nearly There you go: https://hastebin.com/ovesegufev.cpp
This is what i use and what works good for me0 -
Perfect. That works0