Esempio n. 1
0
 private void OnControllerColliderHit(ControllerColliderHit hit)
 {
     if (hit.normal.y < 0f)
     {
         return;  // Normal is pointing down so mustn't be ground
     }
     if (hit.normal.y > groundInfo.Normal.y)
     {
         groundInfo.Distance = transform.position.y - hit.point.y;
         groundInfo.Angle    = UMath.GroundAngle(hit.normal);
         groundInfo.Tag      = hit.collider.tag;
         groundInfo.Normal   = hit.normal;
     }
 }
Esempio n. 2
0
    private void CheckForGround()
    {
        if (groundInfo.Angle > charControl.slopeLimit && groundInfo.Tag != "Slope")
        {
            isGrounded = false;
        }
        else
        {
            isGrounded = charControl.isGrounded;
        }

        // This downwards ray is more accurate than the capsule information
        // its not always available and player gets stuck if its not so we still use collider hits

        RaycastHit hit;

        float castDist = charControl.stepOffset + charControl.skinWidth + charControl.radius;

        Vector3 centerStart = transform.position + Vector3.up * charControl.radius;

        Debug.DrawRay(centerStart, Vector3.down * castDist, Color.blue);
        if (groundedOnSteps && Physics.Raycast(centerStart, Vector3.down, out hit, castDist, ~(1 << 8), QueryTriggerInteraction.Ignore))
        {
            float distance = transform.position.y - hit.point.y;

            // allows player to run of steps properly
            if (distance <= charControl.stepOffset || hit.collider.tag.Equals("Slope"))
            {
                isGrounded = true;

                groundInfo.Distance = distance;
                groundInfo.Angle    = UMath.GroundAngle(hit.normal);
                groundInfo.Tag      = hit.collider.tag;
                groundInfo.Normal   = hit.normal;
            }
        }

        anim.SetBool("isGrounded", isGrounded);
        anim.SetFloat("groundDistance", groundInfo.Distance);
        anim.SetFloat("groundAngle", groundInfo.Angle);
    }