• 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 prezio · Dec 03, 2018 at 01:55 PM · multiplayermultiplayer-networkingcheckpointcheckpoints

How to make multiplayer checkpoint's

How is it possible to make multiplayer checkpoints? I want to achive something like that: For example we've got 2 players: 1Player and 2Player. 1Player is faster than 2Player. If 1Player exceeded first checkpoint it appears him second checkpoint. But 2Player only show first checkpoint. Here is my code to boatcontroller

 void Start()
 {
     if (!isLocalPlayer)
     {
         Destroy(this);
         return;
     }
     cameraOffset = new Vector3(0f, cameraHeight, -cameraDistance);
     mainCamera = Camera.main.transform;
     MoveCamera();
     checkpoint1 = GameObject.FindGameObjectWithTag("CheckPoint");
     checkpoint2 = GameObject.FindGameObjectWithTag("CheckPoint2");
     checkpoint3 = GameObject.FindGameObjectWithTag("CheckPoint3");
     checkpoint4 = GameObject.FindGameObjectWithTag("CheckPoint4");
     checkpoint2.SetActive(false);
     checkpoint3.SetActive(false);
     checkpoint4.SetActive(false);
     
     
 }

 void OnTriggerEnter(Collider other)
 {
     
         if (other.tag == "CheckPoint")
         {
             checkpointReached = true;
             checkpoint1.SetActive(false);
             checkpoint2.SetActive(true);
         }
         if (other.tag == "CheckPoint2")
         {
             checkpointReached2 = true;
             checkpointReached = false;
             checkpoint2.SetActive(false);
             checkpoint3.SetActive(true);
         }
         if (other.tag == "CheckPoint3")
         {
             checkpointReached3 = true;
             checkpointReached2 = false;
             checkpoint3.SetActive(false);
             checkpoint4.SetActive(true);
         }
         if (other.tag == "CheckPoint4")
         {
             checkpointReached3 = false;
             checkpointReached4 = true;

         }
     
 }
 void OnTriggerExit(Collider other)
 {
     if (other.tag == "CheckPoint2")
         checkpointReached = false;
     if (other.tag == "CheckPoint3")
         checkpointReached2 = false;
 }


 void Update()
 {
    
     Balance();

     if (Input.GetKey(KeyCode.A))
         ship.RudderLeft();
     if (Input.GetKey(KeyCode.D))
         ship.RudderRight();

     if (forward)
     {
         if (Input.GetKey(KeyCode.W))
             ship.ThrottleUp();
         else if (Input.GetKey(KeyCode.S))
         {
             ship.ThrottleDown();
             ship.Brake();
         }
     }
     else
     {
         if (Input.GetKey(KeyCode.S))
             ship.ThrottleUp();
         else if (Input.GetKey(KeyCode.W))
         {
             ship.ThrottleDown();
             ship.Brake();
         }
     }

     if (!Input.GetKey(KeyCode.W) && !Input.GetKey(KeyCode.S))
         ship.ThrottleDown();

     if (ship.engine_rpm == 0 && Input.GetKeyDown(KeyCode.S) && forward)
     {
         forward = false;
         ship.Reverse();
     }
     else if (ship.engine_rpm == 0 && Input.GetKeyDown(KeyCode.W) && !forward)
     {
         forward = true;
         ship.Reverse();
     }
     if (checkpointReached==true)
     {
         checkpoint1.SetActive(false);
         checkpoint2.SetActive(true);
     }

 }
 private void FixedUpdate()
 {
     MoveCamera();
 }
 void Balance()
 {
     if (!m_COM)
     {
         m_COM = new GameObject("COM").transform;
         m_COM.SetParent(transform);
     }

     m_COM.position = COM;
     GetComponent<Rigidbody>().centerOfMass = m_COM.position;
 }
 void MoveCamera()
 {
     mainCamera.position = transform.position;
     mainCamera.rotation = transform.rotation;
     mainCamera.Translate(cameraOffset);
     mainCamera.LookAt(transform);
 }

}

And here is my code to checkpoints private void Start() {

     ship.checkpoint1.SetActive(true);
     ship.checkpoint2.SetActive(false);
     ship.checkpoint3.SetActive(false);
     ship.checkpoint4.SetActive(false);

 }
 void Update()
 {
     
     
     if (ship.checkpointReached == true)
     {
         ship.checkpoint2.SetActive(true);
         Vector3 targetPosition = ship.checkpoint2.transform.position;
         targetPosition.y = transform.position.y;
         transform.LookAt(targetPosition);
     }
     else if (ship.checkpointReached2 == true)
     {
         ship.checkpoint3.SetActive(true);
         Vector3 targetPosition = ship.checkpoint3.transform.position;
         targetPosition.y = transform.position.y;
         transform.LookAt(targetPosition);
     }
     else if (ship.checkpointReached3 == true)
     {
         ship.checkpoint4.SetActive(true);
         Vector3 targetPosition = ship.checkpoint4.transform.position;
         targetPosition.y = transform.position.y;
         transform.LookAt(targetPosition);

     }
     else
     {
         Vector3 targetPosition = ship.checkpoint1.transform.position;
         targetPosition.y = transform.position.y;
         transform.LookAt(targetPosition);
     }
     
 }


Comment
Add comment · Show 4
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 BruceKristelijn · Dec 03, 2018 at 03:31 PM 0
Share

What exactly do you want to have happen with these checkpoints? The code can also be way more dynamically written. But can you please allaborate at what you want to achieve?It helps more and will help people more id people awnsering can give some theory aswell.

avatar image prezio BruceKristelijn · Dec 03, 2018 at 03:48 PM 0
Share

For example we've got 2 players: 1Player and 2Player. 1Player is faster than 2Player. If 1Player exceeded first checkpoint it appears him second checkpoint. But 2Player only show first checkpoint.

avatar image BruceKristelijn prezio · Dec 10, 2018 at 04:13 PM 0
Share

You can always get the checkpoints from the server. Then wehn a players hits checkpoint 1 on the server side send a message updating the checkpoint he is on and a message to the player for displaying the changed checkpoint

Show more comments

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

227 People are following this question.

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

Related Questions

How to find local player gameobject? c# 3 Answers

Testing my multiplayer with someone across the country 1 Answer

Many listeners in multiplayer 0 Answers

is mirror unity support local wifi host on android? 0 Answers

[UNET] Syncing the position of a non-player object such as a trap (no player authority whatsoever) 3 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges