public void UpdateLedgeDetectorState(Vector3 pos) { const float bodyRadius = PlayerConstants.BODY_RADIUS; const float distance = 0.13f; // TODO: Add comments, some of them clever. RaycastHit?ceilingHit = CylinderPhysics.CircleCast( pos, bodyRadius, BIG_NUMBER, Vector3.up ); float ceilingHeight = ceilingHit?.distance ?? BIG_NUMBER; Vector3 echoStart = pos + (Vector3.up * ceilingHeight); RaycastHit?echoHit = CylinderPhysics.CircleCast( echoStart, bodyRadius + distance, BIG_NUMBER, Vector3.down ); LedgePresent = echoHit.HasValue; if (LedgePresent) { DebugDisplay.DrawPoint(Color.green, echoHit.Value.point); LastLedgeHeight = echoHit.Value.point.y - pos.y; } }
/// <summary> /// Returns a raycast hit for the ground we're above, /// or null if we're in the air. /// </summary> /// <returns></returns> private RaycastHit?GetGround(Vector3 pos) { return(CylinderPhysics.CircleCast( pos + (Vector3.up * RAYCAST_OFFSET), PlayerConstants.BODY_RADIUS, RAYCAST_DISTANCE, Vector3.down, QueryTriggerInteraction.Ignore )); }