Exemplo n.º 1
0
        public void Shot(Ray ray, float force, float distance)
        {
            Debug.DrawRay(ray.origin, ray.origin + ray.direction * distance, Color.red, 2);

            //check if the ray hits a physic collider
            RaycastHit hit;

            if (_bzRagdoll == null)
            {
                if (!Physics.Raycast(ray, out hit, distance))
                {
                    return;
                }
            }
            else
            {
                if (!_bzRagdoll.Raycast(ray, out hit, distance))
                {
                    return;
                }
            }

            Health -= force;

            Rigidbody hitRigid = hit.rigidbody;

            //check if the raycast target has a rigid body (belongs to the ragdoll)
            if (hitRigid == null || hit.transform.root != transform.root)
            {
                return;
            }

            if (!IsDead())
            {
                return;                 // exit if still alive
            }
            //set the impact target to whatever the ray hit
            _impactTarget = hitRigid;

            //impact direction also according to the ray
            _impactDirection = ray.direction;

            //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;
        }