- Home /
Question by
JuanseCoello · Dec 05, 2014 at 01:41 PM ·
collisionraycastragdollisgrounded
Help with raycast from a ragdoll
I have created a ragdoll that can move similar to a character controller, but now I have an issue with the detection of the collition of the raycast. I want to detect when the ragdoll is grounded, or touching the floor. This is the code that is wrong.
public static Rigidbody rb;
void IsGrounded() {
RaycastHit hitInfo;
if (Physics.Raycast(rb.transform.position + Vector3.down * 5f, Vector3.up * 5f, out hitInfo, Mathf.Infinity))
{
if (hitInfo.distance > 0.5f) // Change .1f to what you need
Debug.DrawRay(rb.transform.position + Vector3.down * 50f, Vector3.up * 50f, Color.blue);
isgrounded = false;
if (hitInfo.distance < 0.5f)
Debug.DrawRay(rb.transform.position + Vector3.down * 50f, Vector3.up * 50f, Color.red);
isgrounded = true;
}
}
// only the void IsGrounded is wrong, everything else is fine by the way
Comment
Your answer
Follow this Question
Related Questions
Ragdoll collision precision 0 Answers
Ragdoll Raycast to Collision 0 Answers
Raycast shooting with prefab 0 Answers