private void Update() { float move = rewiredPlayer.GetAxis(RewiredConsts.Action.Move) * maxSpeed; if (move * move > 0.04f) { animator.SetBool("isWalking", true); spriteContainer.transform.localScale = new Vector3(move >= 0 ? 1f : -1f, 1f, 1f); if (jumpingObject.jumpSensor.isOnGround) { rigidbody2D.MovePosition(transform.position + Vector3.right * (move * maxSpeed * Time.fixedDeltaTime)); } if (!isGameOver && Mathf.Abs(move) > tooFastThreshold) { if (jumpingObject.jumpSensor.isOnGround) { TooFast?.Invoke(Mathf.Abs(move) / maxSpeed - tooFastThreshold); if (!stompClouds.isPlaying) { stompClouds.Play(); } } } else { NormalSpeed?.Invoke(); if (stompClouds.isPlaying) { stompClouds.Stop(); } } } else { animator.SetBool("isWalking", false); } float leftGrasp = rewiredPlayer.GetAxis(RewiredConsts.Action.Grab_Left); float rightGrasp = rewiredPlayer.GetAxis(RewiredConsts.Action.Grab_Right); if (leftGrasp > 0 && rightGrasp > 0 && Mathf.Abs(leftGrasp - rightGrasp) < minGraspDifferenceBetweenHands) { appliedStrength = leftGrasp + rightGrasp; } else { appliedStrength = 0; } animator.SetFloat("eyes", appliedStrength / 2f); if (!isHoldingSomething) { var triggers = Physics2D.CircleCastAll(transform.position, searchingRadius, Vector2.up, 1f); PickableTrigger closestTrigger = null; float minDistance = 100f; globalPiecesController.TurnOffHighlights(); foreach (var trigger in triggers) { if (trigger.collider.gameObject.layer == LayerMask.NameToLayer("BuildPieceSelfCollision")) { var distance = Vector2.Distance(trigger.collider.gameObject.transform.position, transform.position); var t = trigger.collider.gameObject.GetComponent <PickableTrigger>(); if (t != null && t.CanBePicked() && distance < minDistance) { minDistance = distance; closestTrigger = trigger.collider.gameObject.GetComponent <PickableTrigger>(); } } } if (closestTrigger != null) { possiblePick = closestTrigger.GetPickableObject().gameObject; closestTrigger.GetPickableObject().Highlight(true); (Transform, Transform)graspPoints = closestTrigger.GetGraspPoints(); leftHandCustomRestOffset = armsContainer.transform.worldToLocalMatrix * (new Vector3(graspPoints.Item1.localPosition.x, leftHandDefaultOffset.y, 0)); rightHandCustomRestOffset = armsContainer.transform.worldToLocalMatrix * (new Vector3(graspPoints.Item2.localPosition.x, leftHandDefaultOffset.y, 0)); } else { possiblePick = null; leftHandCustomRestOffset = leftHandDefaultOffset; rightHandCustomRestOffset = rightHandDefaultOffset; } desiredLeftHandLocalPosition = leftHandCustomRestOffset; desiredRightHandLocalPosition = rightHandCustomRestOffset; if (appliedStrength > minGraspStrength && arms.CanGrasp && possiblePick != null) { leftHandSprite.sortingOrder = graspingLayer; rightHandSprite.sortingOrder = graspingLayer; pickedObject = possiblePick.GetComponent <PickableObject>(); pickedObject.Grabbed(); isHoldingSomething = true; } else { //leftHand.transform.localPosition = leftHandCustomRestOffset; //rightHand.transform.localPosition = rightHandCustomRestOffset; leftHandSprite.sortingOrder = restingLayer; rightHandSprite.sortingOrder = restingLayer; isHoldingSomething = false; } leftHand.transform.localPosition = leftHandCustomRestOffset + Vector3.right * (graspMovementBias * leftGrasp); rightHand.transform.localPosition = rightHandCustomRestOffset + Vector3.left * (graspMovementBias * rightGrasp); } leftHand.transform.localPosition = Vector3.Lerp(leftHand.transform.localPosition, desiredLeftHandLocalPosition, 0.6f); rightHand.transform.localPosition = Vector3.Lerp(rightHand.transform.localPosition, desiredRightHandLocalPosition, 0.6f); if (isHoldingSomething) { pickedObject.transform.position = armsContainer.transform.position; pickedObject.ApplyGrasp(appliedStrength, graspDamage); if (pickedObject.health == 0) { Drop(); } } if (isHoldingSomething && appliedStrength < Mathf.Max(minGraspStrength - 0.2f, 0f)) { Drop(); } float armsAxis = rewiredPlayer.GetAxis(RewiredConsts.Action.Lift); armsContainer.transform.localPosition = armsDefaultPosition + Vector3.up * (armsAxis * armsMovementBias); }