- Home /
Question by
convictcartel · Dec 26, 2015 at 10:40 AM ·
collisionraycastcolliderragdoll
Ragdoll Raycast to Collision
Hello I have a script where when you click a ragdoll it will fall down, now I want the same effect but when an item tagged as "Collider" hits the ragdoll.. Im unable to figure out how to call the ImpactTarget and Direction based off an item with a differnt script
void Update () {
//if left mouse button clicked
if (Input.GetMouseButtonDown(0))
{
//Get a ray going from the camera through the mouse cursor
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
//check if the ray hits a physic collider
RaycastHit hit; //a local variable that will receive the hit info from the Raycast call below
if (Physics.Raycast(ray,out hit))
{
//check if the raycast target has a rigid body (belongs to the ragdoll)
if (hit.rigidbody!=null)
{
//find the RagdollHelper component and activate ragdolling
RagdollHelper helper=GetComponent<RagdollHelper>();
helper.ragdolled=true;
//set the impact target to whatever the ray hit
impactTarget = hit.rigidbody;
//impact direction also according to the ray
impact = ray.direction * 2.0f;
//the impact will be reapplied for the next 250ms
//to make the connected objects follow even though the simulated body joints
//might stretch
impactEndTime=Time.time+0.25f;
}
}
}
Comment