public bool IsCloserThan(Cover first, Cover second, float threshold) { var firstDistance = Vector3.Distance(_head, first.ClosestPointTo(_head, 0, 0)); var secondDistance = Vector3.Distance(_head, second.ClosestPointTo(_head, 0, 0)); return(firstDistance + threshold < secondDistance); }
/// <summary> /// Checks if the cover is adjacent in the given position. /// </summary> private bool isAdjacent(Cover other, Vector3 position, float minAngle, float maxAngle) { var closest = other.ClosestPointTo(position, 0, 0); var distance = Vector3.Distance(position, closest); if (distance > AdjacentDistance) { return(false); } var closestAngle = other.Angle; var deltaAngle = Mathf.DeltaAngle(Angle, closestAngle); return(deltaAngle >= minAngle && deltaAngle <= maxAngle); }
/// <summary> /// Check if the given cover is fitting. /// </summary> private bool doesCoverFit(Cover cover, bool checkDistance) { if (cover == null || cover.Top < _position.y + 0.5f) { return(false); } var position = _position + cover.Forward * _capsuleRadius; var distance = Vector3.Distance(position, cover.ClosestPointTo(position, 0, 0)); float radius; if (cover == _current.Main) { radius = cover.CheckTall(_position.y) ? _settings.TallSideLeaveRadius : _settings.LowSideLeaveRadius; } else { radius = cover.CheckTall(_position.y) ? _settings.TallSideEnterRadius : _settings.LowSideEnterRadius; } var isInFront = cover.IsInFront(_position, cover == _current.Main) && (cover.IsInFront(_position + cover.Right * radius, cover == _current.Main) || cover.RightAdjacent != null) && (cover.IsInFront(_position + cover.Left * radius, cover == _current.Main) || cover.LeftAdjacent != null); if (checkDistance) { var isOld = isInFront && distance <= _settings.LeaveDistance && cover == _current.Main; if (isOld) { return(true); } var isNew = isInFront && distance <= _settings.EnterDistance && cover != _current.Main; if (isNew) { return(true); } return(false); } else { return(isInFront); } }