void Update() { if (GetBoolArray().SequenceEqual(_oldBools) == false) { _orientation = Orientation.None; DeactiveEdges(); _oldBools = GetBoolArray(); } if (LeftEdge || RightEdge) { Orientation currentOrientation = _orientation; _orientation = OrientationHelper.GetOrientation(transform); if (currentOrientation != _orientation) { DeactiveEdges(); CreateEdges(); } } }
public bool CheckLedgeBelow(Climb intendedClimbingState, DirectionFacing direction, out string animation) { //check the edge in the direction travelling. If it's near enough, move to it and jump unless it's dropless. //else, if the slope is declining, set the current spot as the edge and jump, unless there's a dropless edge and we're only jumping bool nearEdge = false; bool canDrop = true; bool down = intendedClimbingState == Climb.Down; if (intendedClimbingState == Climb.Jump) { intendedClimbingState = direction == DirectionFacing.Left ? Climb.AcrossLeft : Climb.AcrossRight; } if (down == false && _motor.MovementState.PivotCollider != null && _motor.MovementState.PivotCollider.gameObject.layer == LayerMask.NameToLayer(Layers.Ice)) { if (JumpInPlace(direction, canDrop, out animation)) { return(true); } } const float checkWidth = 4f; int layer = direction == DirectionFacing.Right ? _rightClimbLayer : _leftClimbLayer; BoxCollider2D edge = null; try { edge = _motor.MovementState.PivotCollider.gameObject.GetComponentsInChildren <BoxCollider2D>().SingleOrDefault(c => c.gameObject.layer == layer); if (edge == null) { var climbableEdges = _motor.MovementState.PivotCollider.gameObject.GetComponent <ClimbableEdges>(); if (climbableEdges != null) { Orientation orientation = OrientationHelper.GetOrientation(_motor.MovementState.PivotCollider.transform); Collider2D excluded = null; if (orientation == Orientation.Flat) { if (direction == DirectionFacing.Left && climbableEdges.IsLeftCorner && climbableEdges.IsLeftCornerInverted == false) { excluded = climbableEdges.LeftException; } else if (direction == DirectionFacing.Right && climbableEdges.IsRightCorner && climbableEdges.IsRightCornerInverted == false) { excluded = climbableEdges.RightException; } } else if (orientation == Orientation.UpsideDown) { if (direction == DirectionFacing.Left && climbableEdges.IsRightCorner && climbableEdges.IsRightCornerInverted) { excluded = climbableEdges.RightException; } else if (direction == DirectionFacing.Right && climbableEdges.IsLeftCorner && climbableEdges.IsLeftCornerInverted) { excluded = climbableEdges.LeftException; } } if (excluded != null) { edge = excluded.gameObject.GetComponentsInChildren <BoxCollider2D>().SingleOrDefault(c => c.gameObject.layer == layer); } } } } catch (Exception) { } Bounds bounds = _motor.Collider.bounds; bool facingEdge = (_motor.MovementState.LeftEdge && direction == DirectionFacing.Left) || (_motor.MovementState.RightEdge && direction == DirectionFacing.Right); if (edge != null && (facingEdge || EdgeValidator.CanJumpToOrFromEdge(edge, bounds.center, _motor.CrouchedCollider))) { canDrop = edge.CanClimbDown(); var distance = Vector2.Distance(_motor.GetGroundPivotPosition(), edge.transform.position); nearEdge = distance < checkWidth; Bounds projectedBounds = new Bounds( new Vector3( direction == DirectionFacing.Right ? edge.transform.position.x + bounds.extents.x : edge.transform.position.x - bounds.extents.x, edge.transform.position.y + bounds.extents.y), bounds.size); if (nearEdge && ((down && EdgeValidator.CanClimbUpOrDown(edge, _motor.CrouchedCollider)) || (down == false && (CheckLedgeAcross(direction, projectedBounds) || canDrop)))) { CurrentClimbingState = GetClimbingState(intendedClimbingState, edge); if (down) { animation = EdgeValidator.CanHang(edge, _motor.StandingCollider) == false ? Animations.HopDown : _motor.Anim.GetBool(PlayerAnimBool.Moving) ? Animations.RollDown : Animations.ClimbDown; } else { animation = Animations.DiveAcross; } return(true); } } if (edge == null && down && facingEdge) { CurrentClimbingState = GetStaticClimbingState(); animation = Animations.HopDown; _exception = null; return(true); } bool downhill = _motor.MovementState.NormalDirection == direction && Vector2.Angle(Vector2.up, _motor.MovementState.Normal) > 20f; if (downhill && down == false) { _exception = edge; if (JumpInPlace(direction, canDrop, out animation)) { return(true); } } animation = ""; return(false); }