/// <summary> /// Check if target is within line of sight /// </summary> private bool IsWithinSight(Transform target, string tag = "", ProximityHelpers.DistanceDirection distanceDirection = ProximityHelpers.DistanceDirection.ALL) { if (target == null || (!string.IsNullOrEmpty(tag) && target.tag != tag)) { return(false); } return(ProximityHelpers.IsWithinSight(transform, target, FieldOfViewAngle, SqrViewMagnitude, distanceDirection)); }
/// <summary> /// Focus on transform and change interaction state /// </summary> /// <returns> /// Wether or not the function was successful /// </returns> public bool AttractMyAttention_ToTransform(Transform target, bool force, StatesInteraction interactionState = StatesInteraction.Interactor, ProximityHelpers.DistanceDirection distanceDirection = ProximityHelpers.DistanceDirection.ALL) { if (IsWithinDistance(DistanceType.INTERACTION, target, distanceDirection) || force) { if (ChangeInteractionState(interactionState, force)) { FocusOnTransform(target); //CurrentInteractionState = interactionState; return(true); } } return(false); }
/// <summary> /// Check if bot is within desired distance of FocusedOnPosition or FocusedOnTransform /// </summary> public bool IsWithinDistance(DistanceType distanceType, ProximityHelpers.DistanceDirection direction = ProximityHelpers.DistanceDirection.ALL, float percent = 1.0f) { if (FocusedOnTransform != null) { return(IsWithinDistance(distanceType, FocusedOnTransform.position, direction, percent)); } else if (FocusedOnPosition != null) { return(IsWithinDistance(distanceType, FocusedOnPosition.Value, direction, percent)); } return(false); }
/* * public Vector3 CalculateOffset(Vector3 peerTetherPosition, ProximityHelpers.DistanceDirection direction) * { * CachedOffset = GetPositionDifference() - GetPositionDifference(peerTetherPosition); * switch (direction) * { * case ProximityHelpers.DistanceDirection.HORIZONTAL: * CachedOffset = new Vector3(CachedOffset.x, 0f, CachedOffset.z); * break; * case ProximityHelpers.DistanceDirection.VERTICAL: * CachedOffset = new Vector3(0f, CachedOffset.y, 0f); * break; * } * return CachedOffset; * } */ public Vector3 CalculateOffset(Vector3 peerPositionDifference, ProximityHelpers.DistanceDirection direction) { CachedOffset = GetPositionDifference() - peerPositionDifference; switch (direction) { case ProximityHelpers.DistanceDirection.HORIZONTAL: CachedOffset = new Vector3(CachedOffset.x, 0f, CachedOffset.z); break; case ProximityHelpers.DistanceDirection.VERTICAL: CachedOffset = new Vector3(0f, CachedOffset.y, 0f); break; } return(CachedOffset); }
/// <summary> /// Check if bot is within desired distance of a position /// </summary> public bool IsWithinDistance(DistanceType distanceType, Vector3 position, ProximityHelpers.DistanceDirection direction = ProximityHelpers.DistanceDirection.ALL, float percent = 1.0f) { float sqrMagnitude = 0f; switch (distanceType) { case DistanceType.AT_POSITION: if (SqrAtPositionErrorMargin == 0) { return(transform.position == position); } sqrMagnitude = SqrAtPositionErrorMargin; break; case DistanceType.PERSONAL_SPACE: sqrMagnitude = SqrPersonalSpaceMagnitude; break; case DistanceType.INTERACTION: sqrMagnitude = SqrInteractionMagnitude; break; case DistanceType.AWARENESS: case DistanceType.OUTSIDE_AWARENESS: sqrMagnitude = SqrAwarenessMagnitude; break; } bool result = ProximityHelpers.IsWithinDistance(ColliderComponent, position, sqrMagnitude * percent, direction) || ProximityHelpers.IsWithinDistance(transform.position, position, sqrMagnitude * percent, direction); if (distanceType == DistanceType.OUTSIDE_AWARENESS) { return(!result); } return(result); }
public void UnfocusAndForgetWhenNotInSight(ProximityHelpers.DistanceDirection distanceDirection = ProximityHelpers.DistanceDirection.ALL) { var target = BotComponent.FocusedOnTransform; BotComponent.UnFocus(() => IsWithinSight(target, "", distanceDirection)); }
/// <summary> /// Return transforms within sight that are being looked out for /// </summary> /// <param name="newTransformsOnly">Only return transforms that have not been "noticed" before</param> public T[] DoLookoutFor <T>(bool newTransformsOnly = true, bool refreshList = false, string tag = "", int?layer = null, ProximityHelpers.DistanceDirection distanceDirection = ProximityHelpers.DistanceDirection.ALL) where T : MonoBehaviour { IEnumerable <T> targets; targets = GetWithinSight <T>(refreshList, tag, layer, distanceDirection); T[] result = new T[0]; if (newTransformsOnly) { result = targets.Where(t => !BotComponent.NoticedTransforms.Contains(t.transform)).Cast <T>().ToArray(); } for (int i = 0; i < result.Length; i++) { OnTransformSeen.Invoke(result[i].transform); } return(result); }
/// <summary> /// Return transforms to look out for that are within line of sight /// </summary> /// <param name="refreshList">Check if new transforms have been spawned</param> public IEnumerable <T> GetWithinSight <T>(bool refreshList = false, string tag = "", int?layer = null, ProximityHelpers.DistanceDirection distanceDirection = ProximityHelpers.DistanceDirection.ALL) where T : MonoBehaviour { return(GetAllLookOutForTransforms(layer, refreshList).Where(t => IsWithinSight(t, tag, distanceDirection) && t.GetComponent <T>() != null).Select(t => t.GetComponent <T>()));; }
/// <summary> /// Return transforms to look out for that are within line of sight /// </summary> /// <param name="refreshList">Check if new transforms have been spawned</param> public IEnumerable <Transform> GetTransformsWithinSight(bool refreshList = false, string tag = "", int?layer = null, ProximityHelpers.DistanceDirection distanceDirection = ProximityHelpers.DistanceDirection.ALL) { return(GetAllLookOutForTransforms(layer, refreshList).Where(t => IsWithinSight(t, tag, distanceDirection))); }
/// <summary> /// Check if transforms to look out for are within line of sight /// </summary> public virtual bool IsWithinSight <T>(string tag = "", ProximityHelpers.DistanceDirection distanceDirection = ProximityHelpers.DistanceDirection.ALL) where T : MonoBehaviour { return(GetAllLookOutForTransforms().Any(t => IsWithinSight(t, tag, distanceDirection) && t.GetComponent <T>() != null)); }
/// <summary> /// Check if transforms to look out for are within line of sight /// </summary> public virtual bool IsWithinSight(string tag = "", ProximityHelpers.DistanceDirection distanceDirection = ProximityHelpers.DistanceDirection.ALL) { return(GetAllLookOutForTransforms().Any(t => IsWithinSight(t, tag, distanceDirection))); }
/// <summary> /// Check if bot is within desired distance of a target /// </summary> public bool IsWithinDistance(DistanceType distanceType, Transform target, ProximityHelpers.DistanceDirection direction = ProximityHelpers.DistanceDirection.ALL, float percent = 1.0f) { return(IsWithinDistance(distanceType, target.position, direction, percent)); }