void CreateTowelLimit() { ChainFinder leftChain = leftGrabbed.GetComponent <ChainFinder>(); ChainFinder rightChain = rightGrabbed.GetComponent <ChainFinder>(); Transform[] chain; float lengthLimit = 0; if (leftChain.index > rightChain.index) { chain = rightChain.GetChainToIndex(leftChain.index); lengthLimit = rightChain.GetMaxLengthToIndex(leftChain.index); } else { chain = leftChain.GetChainToIndex(rightChain.index); lengthLimit = leftChain.GetMaxLengthToIndex(rightChain.index); } foreach (Transform link in chain) { link.BroadcastMessage("SetGrabbed", true); } debugList = chain; MovementLimiter limiter = new MovementLimiter(leftHand, rightHand, lengthLimit, true, true, chain, 0.175f * 2f); handsLimiter = limiter; // Debug.Log("created towel limit"); }
void CheckIfLimiterIsNeeded() { if (leftGrabbed != null && rightGrabbed != null) { if (leftGrabbed != lastFrameLeftGrabbed || rightGrabbed != lastFrameRightGrabbed) { // if both hands are grabbing the towel if (leftGrabbed.gameObject.layer == LayerMask.NameToLayer("Towel") && rightGrabbed.gameObject.layer == LayerMask.NameToLayer("Towel")) { //enact the limit on it CreateTowelLimit(); } } } else { if (handsLimiter != null) { foreach (Transform link in handsLimiter.chain) { link.BroadcastMessage("SetGrabbed", false); } handsLimiter = null; } } }
// Update is called once per frame void Update() { wait += Time.deltaTime; if (autoCorrectNextFrame && rj != null) { rj.autoConfigureOffset = false; autoCorrectNextFrame = false; } // if you are grabbing this frame and you arent holding anything, and it isnt something the other hand is holding if (hand.grabbedThisFrame() && (grabbedGO == null || grabbedGO.layer == LayerMask.NameToLayer("Ignore Player"))) { float distFromGrab = 999; GameObject tempGrabbedGO = null; // grab check Collider2D[] cols = Physics2D.OverlapCircleAll(handCenter.position.XY(), 0.15f); GameObject staticGrabbed = null; foreach (Collider2D col in cols) { if (col.tag == "Grabbable" || col.tag == "GrabbableKeepRotation") { // Debug.Log("over grabbable"); float dist = Vector2.Distance(col.transform.position.XY(), transform.position.XY()); if (dist < distFromGrab) // make sure we are grabbing the closest object { tempGrabbedGO = col.gameObject; distFromGrab = dist; } } if (col.tag == "Ground") { staticGrabbed = col.gameObject; } } if (tempGrabbedGO != null) // if the other hand is not holding the object, grab it { if (!OtherHandIsHolding(tempGrabbedGO.transform)) { Grabbed(tempGrabbedGO); } } else // if we grabbed nothing, open hand { if (staticGrabbed != null) { Grabbed(staticGrabbed, true); } else { hand.grabbing = false; } } } // If you are grabbing an object if (grabbed && grabbedGO != null) { // Debug.Log(changeInAngle); if (hand.openedThisFrame()) // if you open your hand, release the object { // if you grabbed the soap, check the apply soap as grabbed ApplySoap soap = grabbedGO.GetComponent <ApplySoap>(); if (soap != null) { soap.grabbed = false; } if (moveLimit != null) { handLimiter.handsLimiter = null; moveLimit = null; } //if(!grabbedStatic) Release(1000, grabbedStatic); } if (rj != null && !grabbedStatic) { if (Vector2.Distance(handRB.position, grabbedGO.transform.position.XY()) > 0.75f) { //Release(); } } } // waits a frame to turn on grabbed collider so it shoots in the correct direction if (grabbedGO != null && !grabbed) { Collider2D col = Physics2D.OverlapCircle(grabbedGO.transform.position.XY(), 0.5f, Constants.player.playerLayer); if (wait >= waitToBringBackCollider && col == null) { if (!grabbedStatic) { grabbedGO.layer = LayerMask.NameToLayer(storedLayerName); } grabbedGO.GetComponent <Rigidbody2D>().freezeRotation = false; grabbedGO = null; } } if (grabbedGO != null && grabbed && !grabbedStatic && !stillRotates) { grabbedGO.transform.eulerAngles = new Vector3(grabbedGO.transform.eulerAngles.x, grabbedGO.transform.eulerAngles.y, -Extensions.Angle(-transform.up) - angleOffset); } if (hand.isClosed()) { hand.GetComponent <Collider2D>().enabled = true; } else { hand.GetComponent <Collider2D>().enabled = false; } if (dtj != null) { dtj.Update(); } }