- Home /
Check if player is on track
Let's say I have an image for track, a white line on a black background. And my player can move accordingly to the mouse position. How can I check if the player got off the track so I can stop the game? I tried with physics2D colliders but it's pretty hard work because my track it's not only straight lines. It has some curves too. Do I have another option for this? Or I need to add Pollygon2D components all over the place?
Answer by revapps · Jul 20, 2014 at 03:33 PM
You'll have to use polygon 2D colliders and set them each as a trigger.
I've tried with that already. Is there a way to create Physics2D Polygon and then Reverse Select? Because right now is selecting the road, and I want to select everything except the road..
Unfortunately, no. If possible, I would recommend you make the entire track a separate object and then apply a polygon collider.
Here's another solution, however, it is more complex. If your player is moving along the x axis, keep checking the mouses y position. If the mouse goes above or below the y range, end the game. Wherever there are curves, you can set a trigger there to change the $$anonymous$$imum and maximum y position. This will be more complex to implement if both your x and y $$anonymous$$ max are changing.