Question by
j_masters · Feb 09, 2017 at 03:58 PM ·
respawncheckpoint
Platformer multiple checkpoints help
Hello!
I'm trying to get a checkpoint system working for a 2 player head to head platformer. Right now the player respawns at the first checkpoint when it falls off the stage and hits a collider. However Im having trouble making the new checkpoint (A gameobject with a collider attached) send its position to the fall off stage collider.
Any help will be appreciated :D
public class Respawn : MonoBehaviour {
public GameObject P1; //The player as a gameobject.
public Vector2 currentPosition; //
public Transform checkPoint;
void OnTriggerEnter(Collider other) {
//When the player hits the respawn death collider start the respawner function.
StartCoroutine (Respawner ());
}
IEnumerator Respawner() {
currentPosition = P1.transform.position;
//Move the players transform to the position of the checkpoint.
P1.transform.position = checkPoint.position;
//Change the move force component in the player controller script to 0
PlayerController.moveForce = 0;
//Delay the player from moving for 1 second after respawn.....gives time to get their bearings.
yield return new WaitForSeconds (1f);
//Change the move force component back to start speed.
PlayerController.moveForce = 25;
Debug.Log ("Death");
}
}
public class CheckPoint : MonoBehaviour {
public Respawn respawn;
public Transform currentCheckPoint;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnTriggerEnter(Collider other) {
//Send this checkpoint position to the respawn killzone.
currentCheckPoint.transform.position = respawn.checkPoint.position;
}
}
Comment