- Home /
how to have an object respawn if it passes a certain point
In my Unity project, the player picks up a tennis raquet and a ball, and tries to hit the ball with the raquet into a target on a wall (this is a virtual reality Unity project). The player is in a fenced backyard. What I am wanting is for if when the player hits the ball and it goes over the fence, the ball respawns in the backyard so that the player can pick the ball back up and try again. All answers are appreciated.
have you used void OnTriggerEnter(Collider col){} before?
Answer by TanselAltinel · Feb 19, 2019 at 02:31 PM
There are many different approaches that can be taken.
First comes to mind as to use Trigger Collision to see if the ball is out of the play area, or has gone into the outside area. For that, please check: https://docs.unity3d.com/ScriptReference/Collider.OnTriggerEnter.html
You can check the distance from a specific area: https://docs.unity3d.com/ScriptReference/Vector3.Distance.html
Depending on your preference and project setup, please refer to the documentations provided in the document links.
Your answer
Follow this Question
Related Questions
Moving an object forward, killing the object and respawning a new one. 1 Answer
multiplayer die and respawn 0 Answers
GUI.Button Not Working Correctly Strange 1 Answer
Re-spawning issue 1 Answer