Search Unity

Ragdoll/Raycast/Collider problem.

Discussion in 'Scripting' started by artosking, Nov 24, 2017.

  1. artosking

    artosking

    Joined:
    Jun 15, 2014
    Posts:
    5
    Hey guys. I'm working on a project where i need a ragdoll with mecanim on my player. I also need a script to check if the player is "grounded" (because player will fall from time to time).

    Ragdoll works fine. Mecanim works fine. And here is a script to check if is grounded:

    Code (CSharp):
    1. void IsGroundedMethod ()
    2.     {
    3.         if (Physics.Raycast (transform.position + vector2, Vector3.down, 0.5f)) // || Physics.Raycast (transform.position + new Vector3 (0, 0, -0.3f), Vector3.down,0.5f))
    4.         {
    5.             Debug.DrawRay(transform.position + vector, Vector3.down, Color.red);
    6.             isGrounded = true;
    7.             anim.SetBool("IsGrounded",true);
    8.             anim.SetBool("Fall",false);
    9.         }
    10.         else {
    11.             isGrounded = false;
    12.             anim.SetBool("Move",false);
    13.             anim.SetBool("IsGrounded",false);
    14.             anim.SetBool ("Fall", true);
    15.         }
    16.     }
    Problem mostly is this: script is checking that the player is grounded, but moment later it changes isGrounded to false.

    What i have also noticed is that, that sometimes player model's feet sometimes go into the ground, and also colliders don't collide. Here a short video:


    any ideas?