- Home /
Trigger respawn after collision?
So I am working on this diving game prototype that I posted about earlier, and I am a complete 'tard when it comes to scripting so I therefore need some help with this one.
I need the make the player respawn back on top at the diving board a couple of seconds after hitting the water.
I tried to look at the Lerpz 3D tutorial, but can't seem to figure out how to make it work in my own project. Any clues on how to do this?
What I think I understand by now is that I should create a collision object in the water that makes the player respawn at a selectet position (spawnpoint) after hitting it.
Answer by Mike 3 · Jul 12, 2010 at 09:51 AM
You can attach something like this to your water, though you'll have to make sure the player has a rigidbody and collider, and the water has a trigger collider:
var spawn : Transform; //drag your spawn point to here in the inspector - probably make it an empty gameobject so you can move it about on the diving board
function OnTriggerEnter(other : Collider) { if (cother.tag == "Player") { other.transform.position = spawn.position; } }
What is this in Ive tried java c# and Boo it works in java but says it doesnt reconize the cother part. Please help.
i think thats a typo it has to be other.tag == "Player
Answer by ZubakIVAN · Jan 10, 2018 at 11:25 PM
For 2D script looks like this:
var spawn :
function OnTriggerEnter2D(other : Collider2D) {
if (other.tag == "Player")
{
other.transform.position = spawn.position;
}
}