- Home /
Respawn on Collision Problems.
Hello everyone, I have a problem as the title, due to the respawn of the character when it collides with something, I have already tried to use scripts from other users who have asked almost the same thing here on Answers. Using this script my character when it collides with an obstacle in the map, nothing happens! Currently it may serve, in my character use a script to make it move forward automatically, and it works, but I do not know if it can cause problems with the script respawn.
Script to move forward is this:
#pragma strict
var Speed : int;
function Update() {
transform.Translate(0, 0, (Speed) * Time.deltaTime);
}
Script for Respawn is this :
private var dead = false;
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "Collision")
{
dead = true;
}
}
function Update()
{
//Here I put the script movement (right, left) and the jump.
}
function LateUpdate()
{
if(dead)
{
transform.position = Vector3(120,9.8,0);
dead = false;
}
}
Hierarchy of the character is this:
Folder1: Player (Forward Script), Main Camera. SubFolder of Folder1 : Character (Respawn and Movement Script)
Any Ideas ? :O
EDIT: [ The game is similar to the style of Temple Run ]
Answer by Ceriath · Sep 25, 2013 at 02:46 PM
Why do you use that LateUpdate()? i would try using
function OnControllerColliderHit(hit : ControllerColliderHit)
{
if(hit.gameObject.tag == "Collision")
{
transform.position = Vector3(120,9.8,0);
}
}
Another thing is that you have to attach that script to the Controller, and i think your "Player" is the controller and not the "character" or what is that "character?
The last thing i would look up: is the tag of the object that you hit really "Collision"?
Answer by Visual Programmer · Sep 25, 2013 at 03:37 PM
You need to make sure the collider has isTrigger checked.
Your answer
Follow this Question
Related Questions
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Setting Scroll View Width GUILayout 1 Answer
Semi colon placement? unity error message 2 Answers
Trouble with a respawn script 1 Answer
Ball jumping mechanic, scrip errors. 1 Answer