- Home /
help with death zone/respawn
I am trying to get my character to respawn if they fall off a platform into a deathzone. The character just keeps falling through the deathzone instead of respawning. Here is the code attached to a simple sphere. Any help is appreciated.
var speed = 3.0; var rotateSpeed = 3.0; private var dead = false;
function OnControllerColliderHit(hit : ControllerColliderHit) { if(hit.gameObject.tag == "fallout") { dead = true; //substract life here } }
function Update () { var controller : CharacterController = GetComponent(CharacterController); transform.Rotate(0, Input.GetAxis ("Horizontal") * rotateSpeed, 0);
var forward = transform.TransformDirection(Vector3.forward);
var curSpeed = speed * Input.GetAxis ("Vertical");
controller.SimpleMove(forward * curSpeed);
} function LateUpdate() { if(dead) { transform.position = Vector3(0,1.4,0); gameObject.Find("Main Camera").transform.position = Vector3(0,2,-1); dead = false; } }
@script RequireComponent(CharacterController)
Please indent all your code by 4 spaces to get it correctly formatted. I did it for you this time.
Answer by Ashkan_gc · Feb 10, 2010 at 04:22 AM
your death zone collider should be a kinematic rigidbody to work. as i know character controller don't work with triggers.