L
L
Luntik942016-03-16 23:53:21
C++ / C#
Luntik94, 2016-03-16 23:53:21

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

    }
}

d2c7b4ca118e4af0953a7a839749f214.jpg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Deerenaros, 2016-03-17
@Luntik94

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 question

Ask a Question

731 491 924 answers to any question