Hi there, Im stuck with a problem since at least 2 weeks.
I searched for lot of info and forums and stuff but nothing.
I want my character dying every time I fall from 8 meter or more.
Is there a simple way to script this . My environement is huge and lot of denivelation. Can I script something without having a huge empty plane to detect the collision ?
What im trying to script with no success is to register the last time I was on the ground ( Y position ), register the next position grounded ( Y position ) and make the difference, if the difference is 8 or more kill my avatar.
I would do exactly the same thing: measure the fall height from the last grounded position to the new ground location, and apply damage or kill the player, depending on the height. If you’re character is a CharacterController, you can do the following:
var falling: boolean = false; // tells when the player is falling
private var lastY: float; // last grounded height
private var character: CharacterController;
function Start(){
character = GetComponent(CharacterController);
lastY = transform.position.y;
}
function Update(){
if (character.isGrounded == false){ // if character not grounded...
falling = true; // assume it's falling
} else { // if character grounded...
if (falling){ // but was falling last update...
var hFall = lastY - transform.position.y; // calculate the fall height...
if (hFall > 8){ // then check the damage/death
// player is dead
}
}
lastY = transform.position.y; // update lastY when character grounded
}
}