- Home /
How to check distance between two players (photon multiplayer)
hi, how would you check the distance between two players in photon, using vector3.distance. I'm kind off new to multiplayer.
(c#)
I hope you have solved this already. Can you please post it here?
Answer by jmgek · May 18, 2016 at 06:51 PM
You have to think of networking a little bit differently. This of it like this: When you run your game each client creates everything on their build. All that is being passed is that data that you want, in this case the transforms of the player position. When receiving data you then apply that data to the player from it's photon ID.
Example: Player 2 starts his game, and then creates a instance of player 1 and 2 in his game.
player 1 is at Vector(0,0,0) and moves to Vector(5,0,0)
player 2 sees HIS instance of player 1 still at Vector(0,0,0) becase nothing has been updated.
Player 1 sends position of new vector to network.
network sends to each player (Dependent on what RPC or what observe mode you have)
Player 2 Receives the new vector and applies that vector to HIS instance of player 1
At any time player 1 or 2 could have done a distance check to see how far apart they are, there is little difference between networking and non networking other than the way you handle properties.
how should you access them in code though? (mainly asking for player 2's transform from player 1's script)
Answer by fillefilip8 · May 18, 2016 at 06:06 PM
@arain55 Just do like normal Vector3.Distance(player1gameObject.transform.position, player2gameObject.transform.position);
Can you please explain this. I tried above code inside my player controller script. and its not working.
Your answer
Follow this Question
Related Questions
How do I set up multiplayer? 0 Answers
[PHOTON PUN] Players cant shoot each other? 1 Answer
Help with basic photon cloud multiplayer control. 0 Answers
Photon timer issue 2 Answers
Multiplayer Change Scene 0 Answers