- Home /
Falling off respawn
Greetings, I am currently creating a game where you have to jump from one cube to another and not fall off. I was wondering if there was any way that I could make it so the player respawns at the original spawn point after falling a little distance. Does anyone have scripts for my request?
By "after falling a little distance" do you mean relative to the last cube you where standing on or to a certain y height?
Answer by deltamish · Oct 28, 2012 at 03:35 PM
Yeah like he said Step1. Create a Cube scale it so that it covers the whole game arena then remove mehfilter nad mesh renderer component from it.
Add this script
var Player:Transform;
var spawn:Transform;
function OnTriggerEnter(col:Collider) {
if(col.tag =="Player"){
//your death script
Instantiate(Player,spawn.position,spawn.rotation):
}
}
Read your comment All this does is checks if something collides with it,It checks wether it has the tag Player or not if it does then it respawns the player and if have a death code it kills the player
if you have no experience in scripting then how did you make the player to run,jump with anims
Note.This script is fixed and is in working condition
Answer by Piflik · Oct 28, 2012 at 03:16 PM
I'd just place a collider somewhere below all the boxes, and when the player collides with it, he gets transported back to the spawn point.
Take an Empty, add a box collider and scale it up until it covers the complete level, move it down to the depth at which you want the player to respawn, add a script to move the player to the spawnpoint OnTriggerEnter (either add this to the player or the collider...doesn't really matter). I would advise against destroying the player and instantiating a new one, since properties could have been changed and you might loose them.
Personally I would add a spawn-function to the player script, that I also use OnStart to initialize the player, and then just call that function when the player hits the trigger.
Answer by Dexter.Unity · Oct 28, 2012 at 04:14 PM
I think you can also simple check your character's y position and if it is lower than your 'you died'.y it will respawn:
var deathHeight : float = -5;
if(transform.position.y <= deathHeight){
Respawn();
}
I am having a very hard time with this as I am quite new to Unity. $$anonymous$$ay you explain in detail exactly what I do to have the player respawn on the original spawn point after falling off? I already created a invisible large rectangle under the map so the player falls off and lands on it. Now what do I do after this? How do I make it so the player teleport to the spawn point after hitting the invisible platform?
I have no prior experience with scripting and what you people are saying is very confusing to me.
Answer by Dexter.Unity · Oct 28, 2012 at 05:10 PM
I am new too, haha so I'll give it a shot :)
If you place this script on your character you can probably use the following:
this is in JavaScript and untested --
var deathHeight : float = -5; // The amount of meter's under your playing platform your character is allowed to be before it has to be respawned
function Update () { // If the character is below or at the deathHeight -> respawn; if(transform.position.y <= deathHeight){ transform.position = Vector3(0, 0, 0); } }
This should place your character back at 0,0,0 when the charact's y position in the world has been -5 or lower than -5. Please tell me if it worked :)
If you put the script you already have on here, it's probably easier to help. What is the error you are getting?
This did not work for me :( just went straight through it! Help?
Your answer
Follow this Question
Related Questions
Respawn after falling off script? 2 Answers
Falling off respawn script 1 Answer
Checki f Player is within area? C# 1 Answer
How do you make a respawn and checkpoint script? 0 Answers
Respawning player not working 2 Answers