Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by nugget70 · May 01, 2015 at 04:08 AM · positionrunnerrace

racer-detecting player position(1st,2nd,3rd,..)

I have four players running around a map how can I detect which one is coming first second third and fourth

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

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by RLin · May 02, 2015 at 04:10 PM

You can set up checkpoints around the map using triggers. Whoever is on the furthest checkpoint is in the lead, and if two people are going to the same checkpoint, you can get the distance to the next checkpoint, and the closer one is leading.

Comment
Add comment · Show 2 · 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 nugget70 · May 11, 2015 at 06:36 AM 0
Share

Thanks for your reply. I understand the logic behind how i should tackle the problem but I'm struggling to code it

avatar image nugget70 · May 11, 2015 at 06:37 AM 0
Share

Ive currently got a race$$anonymous$$anager script and a script on each player that talks to the race manager script letting it know there distance to next waypoint, when the collide into a waypoint and some other variables and it works with two players. The problem is i need 4 players and my code is just a cheap and easy work around

avatar image
0

Answer by nugget70 · May 11, 2015 at 10:13 AM

 using UnityEngine;
 using System.Collections;
 
 public class player : MonoBehaviour {
     public float speed = 5.0f;
     private int checkPointCounter;
     private positionManager PositionManager;
     public Transform currentCheckPoint, nextCheckPoint;
 
 
     // Use this for initialization
     void Start () {
        PositionManager= GameObject.Find("Main Camera").GetComponent<positionManager>();
     }
     
     // Update is called once per frame
     void Update () {
 
         nextCheckPoint = PositionManager.checkPoints[checkPointCounter];
       
 
         PositionManager.p1Distance = Vector3.Distance(transform.position,nextCheckPoint.transform.position);
 
 
         float targetSpeed=Input.GetAxisRaw("Horizontal")*speed;
 
         if (Input.GetKey("d")){
 
             transform.Translate(new Vector2(targetSpeed * Time.deltaTime, 0), Space.World);
 
         }else if (Input.GetKey("a"))
         {
 
             transform.Translate(new Vector2(targetSpeed * Time.deltaTime, 0), Space.World);
 
         }
 
     }
 
     void OnTriggerEnter(Collider other)
     {
         if (other.tag=="checkPoint") {
             if (checkPointCounter ==4)
                 checkPointCounter = -1;
         }
         checkPointCounter++;
 
         PositionManager.checkPointPlayer1 = checkPointCounter;
       
             
     }
 
 }
 
 
 
 
     
 
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 nugget70 · May 11, 2015 at 06:39 AM 0
Share

This is what is attached to my player

avatar image
0

Answer by nugget70 · May 11, 2015 at 10:13 AM

 using UnityEngine;
 using System.Collections;
 
 public class positionManager : MonoBehaviour {
     
     public GameObject p1, p2;
     private player Player;
     private player2 Player2;
     public float p1Distance, p2Distance;
     public int checkPointPlayer1, checkPointPlayer2;
     
     public string [] playerPos={"1st","2nd"};
     public Transform [] checkPoints;
     public bool diffCheckPoint;
 
     // Use this for initialization
     void Start () {
         p1 = GameObject.Find("player1");
         p2 = GameObject.Find("player2");
         Player = p1.GetComponent<player>();
         Player2 = p2.GetComponent<player2>();
 
     }
     
     // Update is called once per frame
     void Update () {
 
 
         if (checkPointPlayer1 == checkPointPlayer2)
         {
             if (p1Distance < p2Distance)
             {
               
                 p1.GetComponentInChildren<TextMesh>().text = playerPos[0];
                 p2.GetComponentInChildren<TextMesh>().text = playerPos[1];
             }
             else {
                 p1.GetComponentInChildren<TextMesh>().text = playerPos[1];
                 p2.GetComponentInChildren<TextMesh>().text = playerPos[0];
             }
             diffCheckPoint = false;
         }
         else {
             diffCheckPoint = true;
             
         }
 
            
     }
 }
 
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 nugget70 · May 11, 2015 at 06:39 AM 0
Share

This is my race manager

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

I need help with a Text Location script (Ho bisogno di aiuto con uno script di posizione del testo) 0 Answers

Setting up player positions in a racing game 1 Answer

Logic on calculating positions in a race. 5 Answers

How to calculate delta offset time between race cars? 0 Answers

How to display Car's Rank in a Racing Game 3 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