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 /
  • Help Room /
avatar image
0
Question by Sivakrishna-karri · Feb 17, 2017 at 10:23 PM · c#unity 5multiplayerphotonpun

Both players reach same time how to get result draw in photon unity

I've been working on a photon multiplayer racing game. The main problem is how to synchronize both players reaching the end line at the same time. My main intention is to show a "Draw/Tie" message to both players.

 void OnCollisionEnter(Collision others)
 {
     if (others.gameObject.tag == "End") 
     {
         Debug.Log ("JJJJJJJJJJ");
         if (m_PhotonView.isMine) 
         {
             GameObject prefab = Instantiate (WinPrefab, new Vector3 (0, 0, 0), Quaternion.identity) as GameObject;
             prefab.transform.SetParent (GameObject.FindGameObjectWithTag ("Canvas").transform, false);
             Debug.Log ("Winner Position"+this.Position);
             Debug.Log ("you are Winner");
             //Invoke ("PositionChange", 3.0f);
             //Destroy (this.gameObject);
             //transform.position = Position;
             //PhotonNetwork.DestroyAll ();
 
         } 
         if (!m_PhotonView.isMine) 
         {
             GameObject prefab = Instantiate (LoosePrefab, new Vector3 (0, 0, 0), Quaternion.identity) as GameObject;
             prefab.transform.SetParent (GameObject.FindGameObjectWithTag ("Canvas").transform, false);
             Debug.Log ("You are looser");
             //Invoke ("PositionChange", 3.0f);
             //Destroy (this.gameObject);
             //PhotonNetwork.DestroyAll ();
         }
 
         if (m_PhotonView.isMine && !m_PhotonView.isMine)
         {
             GameObject prefab = Instantiate (DrawPrefab, new Vector3 (0, 0, 0), Quaternion.identity) as GameObject;
             prefab.transform.SetParent (GameObject.FindGameObjectWithTag ("Canvas").transform, false);
             Debug.Log ("Match Drawn");
 
         }
 
 
         //PhotonNetwork.DestroyAll ();
 
 }


Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by mmciver · Feb 18, 2017 at 04:57 AM

My first reaction would be to add an empty game object at the end collider, and check the distance from the object to each player, if they are the same (or close enough?) then declare it a draw.

However, if the collider they are hitting is flat (and it probably should be) and point at which each player could hit it is not controllable, then the above method could lead to a scenario where the 'losing' player is closer to the game object than the winning player.

My 2nd solution would be to ensure that the end collider is always squarely on one of the axis, so you can simply check the transform.position.x or .y or .z values (whichever is appropriate) to see if which is greater, or if they are equal.

If you can't ensure this situation, then you can modify it by getting the negative normal of the collider plane (so pointing from the collider in the direction of the player motion), then projecting the vector of each player onto this vector and seeing which is greater, or if they are equal.

Comment
Add comment · 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

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

8 People are following this question.

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

Related Questions

How do i use RPC's to set a object active in the hierarchy for all Players in the room and also how do i synchronize UI events focused on a VideoPlayer (Play, Pause etc.)) 0 Answers

PhotonOnSerializeView() Only working sometimes 0 Answers

Photon ccu question 0 Answers

Match making in Photon 0 Answers

Unity Photon Networking Buttons ~ HELP, 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