When joining a room, older clients' sprites start at origin.

Options
I'm making a 2D game in Unity, and I just started using Photon. Right now, when you start the game, you basically just spawn at origin and can walk around.

My problem is that when I start one instance of the game, it works well. My character spawns, then I move him to a new position. Then when I start another instance of the game, it works well too, except that the first player initially appears at origin, then flies to its true position.

I don't have my code at hand right now, but it's basically following the basic tutorial given, I think the Marco Polo tutorial. Also I have Photon View on the character prefab, observing the serialization script which lerps the position of the other clients' characters.

This lerping is obviously causing the object to fly from origin to the true position. But my question is how can I get the character to initially start at its true position, rather than origin?

I saw one thread where someone asked this question, but someone kinda stole the thread away from that guy with a similar but different topic.

Thanks.

Comments

  • Well, the instatiate call for the first player's object is buffered by the server, so his object will inevitably be instantiated at the origin whenever a new player joins. It's actually much harder to have the object instantiate itself in it's "current" position than circumvent the "first-lerp" issue, so:

    You can have a local boolean flag indicating whether your object received the first serialization call or not. If it hasn't, do not interpolate the position and set the flag to true, otherwise just proceed as you have.

    It might be a good idea to not even _draw_ this object on screen until the actual position comes through either (I'm not sure whether Unity or Photon guarantee that serialization comes before the first frame after instantiation). If it's a 2D sprite, just turn off the Image component until the first serialization comes through.
  • Thanks, that's a good idea, better than what I went with probably. I ended up just changing the prefab to make its initial position something far away, (1000,1000,1000) or something. Then with the photontransformview script, there's a variable for teleporting if the object is further away than the number you choose. I think that's how they did it in their RPG Robot tutorial.