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; } }
private void OnCollisionEnter(Collision other) { IRagdoll ragdoll = other.gameObject.GetComponent <IRagdoll>(); if (type != GrabbableTypes.Body && ragdoll != null) { ragdoll.GetRagdoll().GetComponent <CharacterRopeswingController>().LetGo(); } }
// 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; } } } } }
//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); } }