Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by arain55 · Apr 28, 2016 at 08:40 PM · c#multiplayerphotondistancepun

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#)

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image arijitcomm · Mar 19, 2018 at 05:59 PM 0
Share

I hope you have solved this already. Can you please post it here?

2 Replies

· Add your reply
  • Sort: 
avatar image
0

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.

  1. player 1 is at Vector(0,0,0) and moves to Vector(5,0,0)

  2. player 2 sees HIS instance of player 1 still at Vector(0,0,0) becase nothing has been updated.

  3. Player 1 sends position of new vector to network.

  4. network sends to each player (Dependent on what RPC or what observe mode you have)

  5. 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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image atrupb · Nov 12, 2020 at 08:22 AM 0
Share

how should you access them in code though? (mainly asking for player 2's transform from player 1's script)

avatar image
0

Answer by fillefilip8 · May 18, 2016 at 06:06 PM

@arain55 Just do like normal Vector3.Distance(player1gameObject.transform.position, player2gameObject.transform.position);

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image arijitcomm · Mar 19, 2018 at 05:59 PM 0
Share

Can you please explain this. I tried above code inside my player controller script. and its not working.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges