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);
}
}
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.
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.
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