private void WrapRopeAroundObjects() { if (RopePositions.Count == 0) { return; } Vector2 lastRopePoint = RopePositions.Last(); RaycastHit2D playerToCurrentNextHit = Physics2D.Raycast(PlayerPosition, (lastRopePoint - PlayerPosition).normalized, Vector2.Distance(PlayerPosition, lastRopePoint) - 0.1f, PlayerData.whatCanYouAttachTo); if (playerToCurrentNextHit) { CompositeCollider2D platformsCollider = playerToCurrentNextHit.collider as CompositeCollider2D; if (platformsCollider != null) { Vector2 closestPointToHit = platformsCollider.bounds.ClosestPoint(playerToCurrentNextHit.point); if (WrapPointsLookup.ContainsKey(closestPointToHit)) { Player.OnRopeStateFinish.ResetRope(); } else { RopePositions.Add(closestPointToHit); WrapPointsLookup.Add(closestPointToHit, 0); _distanceSet = false; } } } }
public void ResetRope() { Player.RopeJoint.enabled = false; Player.RopeHingeAnchorSpriteRenderer.enabled = false; Player.MyRopeLineRenderer.positionCount = 2; Player.MyRopeLineRenderer.SetPosition(0, PlayerPosition); Player.MyRopeLineRenderer.SetPosition(1, PlayerPosition); WrapPointsLookup.Clear(); RopePositions.Clear(); }
private void UnwrapRopePosition(int anchorIndex, int hingeIndex) { var newAnchorPosition = RopePositions[anchorIndex]; WrapPointsLookup.Remove(RopePositions[hingeIndex]); RopePositions.RemoveAt(hingeIndex); Player.RopeHingeAnchorRigidbody.transform.position = newAnchorPosition; _distanceSet = false; if (_distanceSet) { return; } Player.RopeJoint.distance = Vector2.Distance(PlayerPosition, newAnchorPosition); _distanceSet = true; }