protected virtual void OnDrawGizmosSelected() { if (debugMode) { Gizmos.DrawWireSphere(transform.position, getCoverRange); if (_coverPoints.Count == 0) { return; } for (int i = 0; i < _coverPoints.Count; i++) { var a = Vector3.Angle(_coverPoints[i].transform.forward, threatdir); vAICoverPoint c = _coverPoints[i]; Gizmos.color = a > minAngleOfThreat && !c.isOccuped ? Color.blue : Color.red; Gizmos.DrawSphere(c.posePosition, 0.25f); Gizmos.DrawRay(c.posePosition, Vector3.up); } if (coverPoint) { Gizmos.color = Color.green; Gizmos.DrawSphere(coverPoint.posePosition, 0.25f); Gizmos.DrawRay(coverPoint.posePosition, Vector3.up); Gizmos.DrawSphere(threatPos, 0.2f); Gizmos.DrawRay(threatPos, -threatdir.normalized); Gizmos.DrawRay(threatPos, Vector3.up); Gizmos.color = Color.red * 0.8f; Gizmos.DrawLine(transform.position, threatPos); } } }
public virtual void RemoveCoverPoint() { if (coverPoint) { coverPoint.isOccuped = false; coverPoint = null; } }
internal void OnExitCover() { if (coverPoint) { coverPoint.isOccuped = false; } coverPoint = null; controller.isCrouching = false; }
public virtual void UpdateCoverPoints(Collider[] coverColliders) { _coverPoints.Clear(); for (int i = 0; i < coverColliders.Length; i++) { vAICoverPoint c = coverColliders[i].GetComponent <vAICoverPoint>(); if (c && c.gameObject.CompareTag(coverTag)) { _coverPoints.Add(c); } } }
protected virtual void GetCover(bool forceGet = false) { if (inGetCover) { return; } if (coverPoint && !forceGet && _timeInCover > Time.time) { return; } inGetCover = true; if (_coverPoints.Count == 0 || !HasValidCoversFromPosition(threatdir, threatPos)) { var coverColliders = Physics.OverlapSphere(transform.position, getCoverRange, coverLayer); UpdateCoverPoints(coverColliders); } var dist = maxDistanceOfThreat; var angle = minAngleOfThreat; vAICoverPoint cover = null; for (int i = 0; i < _coverPoints.Count; i++) { var coverP = _coverPoints[i]; if (coverP.isOccuped || !coverP) { continue; } var d = (threatPos - coverP.posePosition).magnitude; var a = Vector3.Angle(coverP.transform.forward, threatdir); if (d < dist && a > angle && (coverP != coverPoint)) { dist = d; cover = coverP; } } if (cover != coverPoint && !isGointToCoverPoint && cover) { if (coverPoint) { coverPoint.isOccuped = false; } coverPoint = cover; coverPoint.isOccuped = true; _coverPoints.Remove(coverPoint); StartCoroutine(GoToCoverPoint()); } inGetCover = false; }
protected virtual void CheckController() { if (!isGointToCoverPoint && ChangeCoverByDamage() && _timeToChangeByDamage < Time.time) { _timeInCover = 0; _timeToChangeByDamage = Time.time + UnityEngine.Random.Range(timeToChangeByDamge.x, timeToChangeByDamge.y); } else if (isGointToCoverPoint && ChangeCoverByDamage()) { _timeToChangeByDamage = Time.time + UnityEngine.Random.Range(timeToChangeByDamge.x, timeToChangeByDamge.y); } if (controller.ragdolled) { controller.isCrouching = false; if (coverPoint) { coverPoint.isOccuped = false; } coverPoint = null; } }
protected virtual void GetCoverOfTarget() { if (inGetCover) { return; } if (_timeInCover > Time.time) { if (coverPoint) { var a = Vector3.Angle(coverPoint.transform.forward, threatdir); if (a > minAngleOfThreat && controller.targetDistance > minDistanceOfThreat && !controller.currentTarget.isLost) { return; } } if (controller.currentTarget.transform && controller.currentTarget.isLost) { if (coverPoint) { coverPoint.isOccuped = false; } coverPoint = null; return; } if (isGointToCoverPoint) { return; } } else if (controller.currentTarget.isLost) { _timeInCover = Time.time + UnityEngine.Random.Range(timeToChangeCover.x, timeToChangeCover.y); if (_coverPoints.Count > 0) { _coverPoints.Clear(); } return; } inGetCover = true; var angle = minAngleOfThreat; if (_coverPoints.Count == 0 || !HasValidCoversFromPosition(threatdir, threatPos)) { var coverColliders = Physics.OverlapSphere(transform.position, getCoverRange, coverLayer); UpdateCoverPoints(coverColliders); } var dist = maxDistanceOfThreat; vAICoverPoint newcoverP = null; for (int i = 0; i < _coverPoints.Count; i++) { var coverp = _coverPoints[i]; var d = (threatPos - coverp.posePosition).magnitude;// Vector3.Distance(controlAI.currentTarget.transform.position, _coverPoints[i].transform.position); var a = Vector3.Angle(coverp.transform.forward, threatdir); if (coverp.isOccuped) { continue; } if ((d < dist && d > minDistanceOfThreat && a > angle) && coverp != coverPoint) { dist = d; newcoverP = coverp; } } if (newcoverP != null && newcoverP != coverPoint && !isGointToCoverPoint) { if (coverPoint) { coverPoint.isOccuped = false; } coverPoint = newcoverP; coverPoint.isOccuped = true; _coverPoints.Remove(coverPoint); StartCoroutine(GoToCoverPointFromTarget()); } inGetCover = false; }