How to check if my player has reached a certain position?

I’ve just started using Unity to create a simple math game for my course, in which if the equation answer is correct I want the character to jump. So far I’ve managed to follow a tutorial to generate platforms and now I want a way to check when the player has reached the edge of the platform, in which case, if the answer is correct it should jump and if not it will fall. How can I check that the players position is at the end of the platform?

I’m not sure what information I need to provide but this is the tutorial I followed: [Unity Endless Runner Tutorial #1 - Player Movement - YouTube] with the only difference that all my platforms are on the same line and are 11x1 in distance.

Good day.

You have different ways to do it. As Sh4d0w08 says, you can use colliders to detect it.

Anopther solution is using the function Vector3.Distance (Position1, Position2) so if this distance is lower than a value, you know they are very very close.

Bye!

Just add an empty object with a collider to the end of the plattform and set it to “is trigger”. Then add a script to this object which calls a function in the PlayerManager-script if the player enters the collider.

private void OnTriggerEnter2D(Collider2D collision)
{
    if (collision.gameObject.CompareTag("Player"))
    {
        GameObject.FindWithTag("Player").GetComponent<NAMEOFPLAYERSCRIPT>().Jump();
    }
}

Add the Jump function to your Player-script (public function!) and manage the jumping there.

You also need to tag your Player with “Player”.

Hope that helps :slight_smile: