What I’m trying to do is whenever the player falls from the main ground and enters hellzone which is placed underneath main ground a function is called.“hellzone” here is a simple plane with isTrigger and isKinematic on , it also has a tag applied to it saying “hell”. On the other hand my player has a rigidbody with isKinematic off and a mesh collider with isTrigger off.
The problem here is that when I enter the “hellzone” nothing happens, my player keeps falling after it slips through “hellzone”.
Here is the script that manipulates all this `
// death from falling
function OnTriggerEnter(other: Collider){
if(other.gameObject.tag=="hell"){
StartCoroutine(Respawn());
Debug.Log("Collided");
}
}
// Respawn
function Respawn(){
GameManager.lives--;
renderer.gameObject.active = false;
yield WaitForSeconds(respawnTime);
transform.position = respawnPoint.position;
renderer.gameObject.active = true;
}
Also, here is the entire player script just in case you need to look through that
var speed:float;
var gravity_:float;
var jumpSpeed:float;
private var grounded = true;
var respawnTime:float = 5.0;
var respawnPoint:Transform;
function Start () {
}
function FixedUpdate () {
// movement
var amtToMove:float = speed*Input.GetAxis("Horizontal")*Time.deltaTime;
transform.Translate(amtToMove,0,0,Space.World);
// Jump implementation
if(Input.GetKeyDown("space")&&grounded){
rigidbody.velocity = Vector3(0,jumpSpeed*Time.deltaTime,0);
}
// gravity implementation
rigidbody.AddForce(Vector3(0,-gravity_*rigidbody.mass*Time.deltaTime,0));
grounded=false;
}
function OnCollisionStay(other:Collision){
// ground check
if(other.gameObject.tag=="ground"){
grounded = true;
}
}
// death from falling
function OnTriggerEnter(other: Collider){
if(other.gameObject.tag=="hell"){
StartCoroutine(Respawn());
Debug.Log("Collided");
}
}
// Respawn
function Respawn(){
GameManager.lives--;
renderer.gameObject.active = false;
yield WaitForSeconds(respawnTime);
transform.position = respawnPoint.position;
renderer.gameObject.active = true;
}