- Home /
How can I cast a ray from a ragdolls child bone? And disable the rest
I know you can cast a ray from the rigidbody, but if i am using a ragdoll with a lot of rigidbodies and colliders, how can I choose only one part of the armature, lets say the hips(I mean the hips green collider), to check collision with the ground. But only raycast from this bone and disable all the rest of the raycasts?
Like this:
I have this script that raycasts to check if the character is grounded
void IsGrounded() {
RaycastHit hitInfo;
if (Physics.Raycast(transform.position + Vector3.up * 0.8f, Vector3.down * 0.5f, out hitInfo, Mathf.Infinity))
{
if (hitInfo.distance > 0.1f) // Change .1f to what you need
Debug.DrawRay(transform.position + Vector3.up * 5f, Vector3.down * 5f, Color.green);
isgrounded = false;
if (hitInfo.distance < 0.1f)
isgrounded = true;
}
}
Answer by Owen-Reynolds · Apr 12, 2014 at 05:11 PM
Raycasts aren't "from" any particular object. The first input, where they start, is just an xyz, anywhere in space.
In your example, it looks up the player's location and tweaks it a little. But transform.position + Vector3.up * 0.8f
is just an xyz. If you increased 0.8, the raycast would kind of be from the head, but really just from where-ever the math said.
If you want the raycast to start from the hips, just look up their position in the usual way, and use that as the first input. If you aren't sure, search around UA for "finding game objects" or "finding children."
To ignore other body parts, a raycast can be made to hit only certain types of things, and ignore the rest. The official name for an object's "type" is a layer. Raycasting and layers also has lots of explanation in UA.
That is not totally true, because I used a rigid body with a collider and a raycast, and tested the raycasr, and it is casted from the collider, I mean the ray starts at the border of the collider, it has not an xyz anywhere in space.
Your answer
Follow this Question
Related Questions
Mouse Over Wont Work on Bone Animated Meshes. 1 Answer
Do animations affect the accuracy of a collider? 0 Answers
Ragdoll Raycast to Collision 0 Answers