Hi there so im working on my fall damage script but im having problems which i cant figure it out im struggling whole day.
Problem is when i get on a ballon which kicks me in the air and when i fell down on floor it works great i die and it waits 2 seconds and im going to respawn, how ever if i fell not from top but walk and then fell under ground it hits the death plane collider it gets bugged out like fps drops to 1 and for 2 seconds it keeps reading dying function the sound the particle and all that and after 2 seconds it goes to respawn and all 3 lifes are gone and end gui shows. I have no idea why its like this, here is my script guys
function Update()
{
if(last_PositionY > player.transform.position.y)
{
fallDistance += last_PositionY - player.transform.position.y;
}
last_PositionY = player.transform.position.y;
if(fallDistance >= 6 && IsGrounded())
{
Debug.Log("YouFell");
BackToNormal();
BreakDeath();
}
if(fallDistance <= 6 && IsGrounded())
{
Debug.Log("LowerThan6");
BackToNormal();
}
function BreakDeath()
{
GetComponent.<Rigidbody>().constraints = RigidbodyConstraints.FreezePositionY | RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezePositionX;
GetComponent.<Renderer>().enabled = false;
yield WaitForSeconds (2);
player.transform.position.x = xaxis;
player.transform.position.y = yaxis;
player.transform.position.z = zaxis;
player.GetComponent.<Rigidbody>().velocity.y = 0;
player.GetComponent.<Rigidbody>().velocity.z = 0;
player.GetComponent.<Rigidbody>().velocity.x = 0;
GetComponent.<Renderer>().enabled = true;
GetComponent.<Rigidbody>().constraints = RigidbodyConstraints.None;
life = life - 1;
health.currentHealth = health.startingHealth;;
healthSlider.value = health.startingHealth;
}
function BackToNormal()
{
fallDistance = 0f;
last_PositionY = 0f;
}
When i set wait for seconds to 0 or remove this line it works perfect but i want when you die it shows where you died for about 2 seconds and then you go to respawn
Edit1 : Also to detect if im ground im using this
function IsGrounded(): boolean
{
return Physics.Raycast(transform.position, -Vector3.up, distToGround + 0.1);
}
Any idea guys ?
Thanks for helping