Game Map Boundaries/Respawn somewhere else when you walk too far off course

So I have a desert area as my map. I want the player to be able to walk around but if they wander too far off into the wrong direction I want a sandstorm to start and for them to spawn back in an area of the map where they’re allowed.

How do I do this? Or can anyone point me towards where I can learn how to do this?

Thanks :smiley:

You could try using Triggers. For that create an Object with for example a BoxCollider attached. Adjust its Volume as needed, and make sure to set it to be a Trigger.

Now, in the OnTriggerEnter function of a script attached to your Trigger-Object you can check if the object that entered your Volume is the player and then handle your sandstorm and set the position of the player back to where you want it.

[1]1

Also be aware that one of the Objects (probably the Player in your example) needs to have a rigidbody attached for the Trigger to work.


  1. Check out the Unity Tutorial on Triggers too! ↩︎