예제 #1
0
    void OnParticleCollision(GameObject other)
    {
        int      numCollisionEvents = part.GetCollisionEvents(other, collisionEvents);
        IRagdoll ragdoll            = other.GetComponent <IRagdoll> ();

        if (ragdoll != null)
        {
            if (!ragdoll.GetIsRagdolled())
            {
                ragdoll.Ragdoll(true, Vector3.zero);
            }
        }

        Rigidbody rb = other.GetComponent <Rigidbody> ();

        for (int i = 0; i < collisionEvents.Count; i++)
        {
            if (ragdoll != null && rb != null)
            {
                Vector3 force = collisionEvents[i].velocity / 5;
                ragdoll.ApplyVelocityToBones(force);
            }
            else if (rb != null)
            {
                Vector3 pos   = collisionEvents[i].intersection;
                Vector3 force = collisionEvents[i].velocity;
                rb.AddForce(force);
            }
        }
    }
    public void Ungrab()
    {
        if (joint != null)
        {
            joint.connectedBody = null;
        }

        if (grabbedObject != null)
        {
            grabbedObject.OnEndGrab?.Invoke(gameObject);
            grabbedObject.rb.isKinematic = false;

            IRagdoll ragdoll = grabbedObject.GetComponent <IRagdoll> ();
            if (ragdoll != null)
            {
                ragdoll.GetRagdoll().transform.parent = null;
            }
            else
            {
                grabbedObject.transform.parent = null;
            }

            grabbedObject = null;
        }
    }
예제 #3
0
    private void OnCollisionEnter(Collision other)
    {
        IRagdoll ragdoll = other.gameObject.GetComponent <IRagdoll>();

        if (type != GrabbableTypes.Body && ragdoll != null)
        {
            ragdoll.GetRagdoll().GetComponent <CharacterRopeswingController>().LetGo();
        }
    }
예제 #4
0
    private void OnTriggerEnter(Collider other)
    {
        IRagdoll  ragdoll = other.GetComponent <IRagdoll> ();
        Rigidbody rb      = other.GetComponent <Rigidbody>();
        Vector3   newDir  = transform.up;

        if (ragdoll != null)
        {
            ragdoll?.Ragdoll(true, newDir * velocity);
            ragdoll.ApplyVelocityToBones(newDir * velocity);
        }
        else if (rb != null)
        {
            rb.velocity = new Vector3(rb.velocity.x, 0, rb.velocity.y) + (newDir * velocity);
        }
    }
예제 #5
0
    // Update is called once per frame

    private void OnCollisionEnter(Collision collision)
    {
        //Get the CharacterRagdoll
        //Get the GrabbableObject and check if its grabbable


        /*.gameObject.GetComponent<CharacterRagdoll>();*/

        IRagdoll ragdoll = collision.gameObject.GetComponent <IRagdoll>();

        if (ragdoll != null)
        {
            GrabbedObject grabbedObject = ragdoll.GetRagdoll().GetComponent <GrabbedObject>();

            if (grabbedObject != null)
            {
                if (grabbedObject.isAttachable) //not entering
                {
                    //Debug.Log("Attachable " + grabbedObject.isAttachable.ToString());
                    if (collision.gameObject.layer != 27)
                    {
                        //look for closest contact points
                        //  loop through all of the contacts points of the enemy
                        // find the point closest to the enemies position

                        //ContactPoint closestPoint;
                        //float closestPointDistance = float.MaxValue;
                        //foreach ( ContactPoint item in collision.contacts)
                        //{
                        //    float pointDistance = Vector3.Distance(item.point, ragdoll.GetRagdoll().hips.position);
                        //    if(pointDistance < closestPointDistance)
                        //    {
                        //        closestPoint = item;

                        //    }
                        //}
                        //AttachObject(ragdoll.GetRagdoll(), closestPoint.point, closestPoint.normal);
                        AttachObject(ragdoll.GetRagdoll(), ragdoll.GetRagdoll().hips.position, collision.contacts[0].normal);
                        grabbedObject.grabbable.isGrabable = false;
                    }
                }
            }
        }
    }
 public void Throw(Vector3 dir)
 {
     if (grabbedObject != null)
     {
         Grabbable toThrow = grabbedObject;
         ReachOut(false);
         IRagdoll ragdoll = toThrow.GetComponent <IRagdoll> ();
         if (ragdoll != null)
         {
             ragdoll.ApplyVelocityToBones(dir * throwSpeed);
         }
         else
         {
             toThrow.rb.velocity = dir * throwSpeed;
         }
         canGrab = false;
         Invoke("EnableGrab", grabResetTime);
     }
 }
    //Raycast from the center of unitychan to hold out her hands
    //If the hand colliders touch a ridgid body link a pivot to them
    //Be able to grab and let go with a button
    public void ReachOut(bool value)
    {
        if (!canGrab)
        {
            return;
        }

        ikActive = value;
        if (grabbedObject == null && value == true)
        {
            //Sphere detect for things to grab
            overlapColliders = Physics.OverlapSphere(holdPoint.position, grabRadius, grabMask);
            foreach (Collider col in overlapColliders)
            {
                Grabbable   grabbable = col.GetComponent <Grabbable> ();
                RopeSegment segment   = col.GetComponent <RopeSegment> ();
                //Rules for all ridgid bodies
                if (segment != null)
                {
                    //Rules for when a rope is grabbed
                    ropeswingController.Grab(segment);
                    break;
                }
                else if (grabbable != null)
                {
                    if (grabbable.isGrabable)
                    {
                        grabbedObject = grabbable;
                        //body.isKinematic = true;

                        IRagdoll ragdoll = grabbedObject.GetComponent <IRagdoll> ();
                        if (ragdoll != null)
                        {
                            ragdoll.GetRagdoll().transform.parent = holdPoint;
                        }
                        else
                        {
                            grabbable.transform.parent = holdPoint;
                        }

                        if (!grabbedObject.isHeavy)
                        {
                            grabbable.transform.position = holdPoint.position;
                            grabbable.transform.rotation = holdPoint.rotation;
                        }
                        if (joint == null)
                        {
                            joint = holdPoint.gameObject.AddComponent <FixedJoint> ();
                        }
                        joint.connectedBody = grabbable.rb;

                        Physics.SyncTransforms();
                        OnObjectGrab?.Invoke(grabbedObject);
                        grabbedObject?.OnGrab?.Invoke(gameObject);
                        break;
                    }
                }
            }
        }

        if (grabbedObject != null && value == false)
        {
            Ungrab();
            OnObjectGrab?.Invoke(null);
        }
    }
예제 #8
0
    // Use this for initialization
    void Start()
    {
        ragdollHelper = GetComponentInChildren<RagdollHelper>();

        animator = GetComponentInChildren<Animator>();
        capsule = GetComponent<Collider>() as CapsuleCollider;

        // as can return null so we need to make sure thats its not before assigning to it
        if (capsule != null)
        {
            originalHeight = capsule.height;
            capsule.center = Vector3.up * originalHeight * half;
        }
        else
        {
            Debug.LogError(" collider cannot be cast to CapsuleCollider");
        }

        rayHitComparer = new RayHitComparer();

        SetUpAnimator();
    }