Well, i have this problem with raycast, I think it’s a bug, not really sure. So i’m using a raycast downwards, so when it’s not touching something, i’m falling, if it is touching, i’m rounded. Well, the first time i fall, i used animations for falling and landing, so i fall, and i land, and i climb somewhere again, and i jump again, that bug happends, i fall, and i don’t land, it thinks i’m still falling. I DON?T KNOW WHY, it just thinks it’s not touching anything, but it actully is touching a floor. But first time, everthing is normal, while 2nd time it happens. Anyone know why ? I’m having problems with this for 3 months now, it’s so annoying i have to double the colliders of floor, so it can see that it’s touching it. Here’s my code, where i setup the raycast:
dist1 = FallToDeathMaxDis;
dir = transform.TransformDirection (Vector3.down);
Debug.DrawRay(transform.position,dir*dist1,Color.green);
if(Physics.Raycast(me.position,dir,dist1))
{
DeathFall = false;
}
else
{
if(CanCheckFalling1 == true)
{
DeathFall = true;
anim.SetBool("FallingDown", true);
Invoke("CheckIfFalling1", 0.50f);
}
}
Doesen’t matter what happens in CheckIfFalling1… It’s just fine, the raycast has a problem.
HERE’S THE FULL CODE !
if(CanFall == true)
{
dist1 = FallToDeathMaxDis;
dir = transform.TransformDirection (Vector3.down);
dist2 = FallDownAliveMaxDis;
Debug.DrawRay(transform.position,dir*dist1,Color.green);
Debug.DrawRay(transform.position,dir*dist2,Color.red);
if(Physics.Raycast(me.position,dir,dist1))
{
DeathFall = false;
}
else
{
if(CanCheckFalling1 == true)
{
DeathFall = true;
anim.SetBool("FallingDown", true);
Invoke("CheckIfFalling1", 0.50f);
}
}
if(Physics.Raycast(me.position,dir,dist2))
{
if(FellAnim == true)
{
FellAnim = false;
Debug.Log ("Roll And Alive");
anim.SetBool("FallingDown", false);
}
else if (DeathFallDeath == true)
{
DeathFallDeath = false;
Debug.Log ("Ragdoll Dead");
RickyRagdoll.position = me.position;
CamPoseCamera.enabled = false;
DeathCamera.enabled = true;
DeathCam.position = CamPos.position;
DeathCam.LookAt(RickyRagdoll);
DeathCam.eulerAngles = new Vector3(90, -90 , 0);
Invoke("SwitchCamera", 1f);
me.position = CharCage.position;
anim.SetBool("FallingDown", false);
}
}
else
{
}
}
void CheckIfFalling1()
{
if (DeathFall == true)
{
CanCheckFalling1 = false;
Invoke("CheckIfFalling2", 0.50f);
}
else
{
CanCheckFalling1 = true;
Debug.Log("Alive");
DeathFall = false;
FellAnim = true;
}
}
void CheckIfFalling2()
{
if (DeathFall == true)
{
CanCheckFalling1 = false;
Invoke("CheckIfFalling3", 0.30f);
}
else
{
CanCheckFalling1 = true;
Debug.Log("Alive");
DeathFall = false;
FellAnim = true;
}
}
void CheckIfFalling3()
{
if (DeathFall == true)
{
CanCheckFalling1 = false;
Debug.Log("Fell to death");
DeathFall = false;
CanFall = false;
DeathFallDeath = true;
}
else
{
CanCheckFalling1 = true;
Debug.Log("Alive");
DeathFall = false;
FellAnim = true;
Debug.Log("Broke leg");
}
}
Made that myself, maybe i did something wrong, and yeah, my script is complicaded.