Answer the question
In order to leave comments, you need to log in
How to write in code the question "When does this object cross the Waypoint (I have it named first_cp)"?
I'm making a racing game, I made Waypoints, I want to write that when the car leaves it, then it appears at the nearest checkpoint, here's my code and a screen
public class Triger : MonoBehaviour
{
public Vector3 moveToPosition;
public float resetTime = 0f;
void OnTriggerEnter(Collider myTrigger)
{
if (myTrigger.gameObject.name != "first_cp")
{
resetTime += Time.deltaTime;
}
if (resetTime > 3)
{
transform.rotation = Quaternion.identity;
transform.position = new Vector3(transform.position.x, transform.position.y + 3, transform.position.z);
resetTime = 0f;
}
}
}
Answer the question
In order to leave comments, you need to log in
I didn’t understand what was needed ... Who interacts with what (collidite)? What is the process logic?
If it is necessary to reset to the last checkpoint in case of going beyond the track, then first these checkpoints must be saved somewhere (you can simply store a link to the object in the static field), and when you get out of the mesh , equate the transform.position and transform.localRotation of the car object with the corresponding checkpoint properties.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question