public override bool CanBeAddedToPlan(AIBrain ai) { if (ai.GetSensor <SensorCanFireNMPositionFinder>().RequestAllInfo(ai) == null) { return(false); } float chance = 0; if (ai.WorldState.CompareKey(DS.takingBulletDamage, true)) { chance = applicapableChanceInBetweenPerc.y; } else { chance = applicapableChanceInBetweenPerc.x; } if ( Random.Range(0, 100) < chance && ai.HaveCurrentTarget() && ai.HaveCurrentWeapon() ) { return(true); } return(false); }
private List <InformationNMCanFirePosition> GetMovePositionS(AIBrain ai) { if (!ai.HaveCurrentTarget()) { return(new List <InformationNMCanFirePosition>()); } angleCheckCount = angleCheckCount <= 2 ? 1 : angleCheckCount; float[] checkAngles = new float[angleCheckCount * 2]; if (angleCheckCount == 1) { checkAngles[0] = (dodgeAnimAnglesInBetween.y - dodgeAnimAnglesInBetween.x) / 2; checkAngles[1] = -checkAngles[0]; } else { float step = (dodgeAnimAnglesInBetween.y - dodgeAnimAnglesInBetween.x) / (float)(angleCheckCount - 1); for (int i = 0; i < angleCheckCount; i++) { checkAngles[i] = dodgeAnimAnglesInBetween.x + step * i; checkAngles[angleCheckCount * 2 - i - 1] = -checkAngles[i]; } } UnityEngine.AI.NavMeshHit hit; RaycastHit hitRc = new RaycastHit(); List <InformationNMCanFirePosition> list = new List <InformationNMCanFirePosition>(); foreach (float angle in checkAngles) { Vector3 startPos = ai.Transform.position + ai.Transform.TransformDirection(Quaternion.AngleAxis(angle, Vector3.up) * Vector3.forward) * dodgeEstimateDistance; #if UNITY_EDITOR if (showShapes) { bool hitb = UnityEngine.AI.NavMesh.SamplePosition(startPos, out hit, .1f, UnityEngine.AI.NavMesh.AllAreas); hitb = !hitb; // dont give me warning Debug.DrawLine(hit.position + Vector3.up * lineCastHeightY, ai.GetCurrentTargetPos() + Vector3.up * lineCastHeightY, Color.black); } #endif if (UnityEngine.AI.NavMesh.SamplePosition(startPos, out hit, .1f, UnityEngine.AI.NavMesh.AllAreas) && hit.hit && Vector3.Distance(hit.position, ai.Transform.position) < (dodgeEstimateDistance + _delta) && Physics.Linecast(hit.position + Vector3.up * lineCastHeightY, ai.GetCurrentTargetPos() + Vector3.up * lineCastHeightY, out hitRc, lineCastMask) && hitRc.transform == ai.InfoCurrentTarget.transform // need to be able to keep shooting ) { #if UNITY_EDITOR if (showShapes) { Debug.DrawRay(hit.position, Vector3.up, Color.green); } #endif list.Add(new InformationNMCanFirePosition(angle, 1, hit.position, 1)); } } return(list); }
public override bool CanBeAddedToPlan(AIBrain ai) { if (ai.HaveCurrentTarget() && ai.HaveCurrentWeapon()) { return(true); } return(false); }
public override bool IsStillValid(AIBrain ai) { if (ai.HaveCurrentTarget()) { return(true); } return(false); }
public override bool CanBeAddedToPlan(AIBrain ai) { if (ai.HaveCurrentTarget() && Time.time - LastUsedAt > minTimeIntervalToAddToPlan) { return(true); } return(false); }
public override bool CanActivate(AIBrain ai) { if (ai.HaveCurrentTarget() && ai.WorldState.CompareKey(DS.isNearCurrentTarget, true)) { return(true); } return(false); }
public override bool CanActivate(AIBrain ai) { if (ai.HaveCurrentTarget() && ai.HaveCurrentWeapon()) { return(true); } return(false); }
public override bool IsStillValid(AIBrain ai) { if (!ai.HaveCurrentTarget() || !ai.GetStateSystem <AIStateSystemWeapon>().HaveAmmoOnClip(ai) || ai.WorldState.CompareKey(DS.isNearCurrentTarget, true)) { return(false); } return(true); }
public override bool CanActivate(AIBrain ai) { infoDodge = sensorSideFinder.RequestInfo <InformationDodgeSide>(ai); if (infoDodge != null && ai.HaveCurrentTarget()) { return(true); } return(false); }
public override bool CanActivate(AIBrain ai) { infoMoveSide = ai.GetSensor <SensorCanFireNMPositionFinder>().RequestInfo(ai); if (infoMoveSide != null && ai.HaveCurrentWeapon() && ai.HaveCurrentTarget()) { return(true); } return(false); }
public override void CalculatePriority(AIBrain ai) { if (!ai.HaveCurrentTarget()) { priority = priorityRange.y; } else { priority = priorityRange.y - (priorityRange.y - priorityRange.x) * (ai.InfoCurrentTarget.OverallConfidence); } }
public override void CalculateCost(AIBrain ai) { if (ai.HaveCurrentTarget()) { float distFromTarget = ai.GetDistanceFromCurrentTarget(); Cost = Mathf.Max(costInBetween.x, costInBetween.y - (Mathf.Clamp01(distFromTarget / minCostAtDistance) * (costInBetween.y - costInBetween.x))); } else { Cost = .5f; } }
public override bool IsApplicapable(AIBrain ai) { bool applyChance = false; if (Time.time - lastUsedAt > minIntervalToSetApplicapable && UnityEngine.Random.Range(0, 100) < activatablePercentage) { applyChance = true; } bool retval = ai.WorldState.CompareKey(DS.haveTarget, true) && ai.WorldState.CompareKey(DS.takingBulletDamage, true) && ai.HaveCurrentTarget() && ai.GetSensor <SensorDodgeSideFinder>().RequestInfo <InformationDodgeSide>(ai) != null && applyChance; if (retval) { lastUsedAt = Time.time; } return(retval); }
public override void CalculateCost(AIBrain ai) { if (ai.HaveCurrentTarget()) { float distance = Vector3.Distance(ai.Transform.position, ai.GetCurrentTargetPos()); if (distance < distanceToSetLowCost) { Cost = lowCost; } else { Cost = 10f; } } else { Cost = 10f; } }
public override bool CanActivate(AIBrain ai) { return(ai.HaveCurrentTarget()); }
public override void OnUpdate(ref bool needToReplan, ref bool needToReevaluateGoals, AIBrain ai) { if (ai.HaveCurrentTarget()) { // target is dead if (ai.InfoCurrentTarget.IsDead || ai.InfoCurrentTarget.transform && ai.InfoCurrentTarget.transform.GetComponent <Health>() && ai.InfoCurrentTarget.transform.GetComponent <Health>().health <= 0 ) { var tempCTarget = ai.InfoCurrentTarget; ai.InfoCurrentTarget = null; ai.WorldState.SetKey(DS.haveTarget, false); needToReplan = true; needToReevaluateGoals = true; tempCTarget.IsDead = true; ai.Memory.BroadcastToListeners(new Messages.AIMessageTargetDead(tempCTarget.BaseTransform)); var susps = ai.Memory.Items.OfType <InformationSuspicion>().Where(x => x.BaseTransform != null && x.BaseTransform == tempCTarget.BaseTransform).ToList(); foreach (var x in susps) { ai.Memory.Remove(x); } } else if (!ai.InfoCurrentTarget.HaveFirePosition) { ai.InfoCurrentTarget = null; ai.WorldState.SetKey(DS.haveTarget, false); needToReplan = true; needToReevaluateGoals = true; } } // Removing current target conditions if (ai.InfoCurrentTarget != null) { if (ai.InfoCurrentTarget.health.Value <= 0 || !ai.InfoCurrentTarget.IsSure) { ai.InfoCurrentTarget = null; ai.WorldState.SetKey(DS.haveTarget, false); needToReplan = true; needToReevaluateGoals = true; } } List <InformationAlive> listFightables = new List <InformationAlive>(ai.Memory.Items.OfType <InformationAlive>()); foreach (var infoFightable in listFightables) { if (infoFightable.IsDead) { var susps = ai.Memory.Items.OfType <InformationSuspicion>().Where(x => x.BaseTransform != null && x.BaseTransform == infoFightable.BaseTransform).ToList(); foreach (var w in susps) { ai.Memory.Remove(w); } //ai.Memory.BroadcastToListeners(ai.Memory.GameObject, infoFightable); continue; } if (infoFightable.IsSure && infoFightable.HaveFirePosition && infoFightable.lastKnownPosition.Confidence > 0 && infoFightable.health.Value > 0) { if (ai.InfoCurrentTarget == null) // there is no target, set it { ai.InfoCurrentTarget = infoFightable; ai.WorldState.SetKey(DS.haveTarget, true); needToReplan = true; // replan when new target is found needToReevaluateGoals = true; targetChangedAt = Time.time; } else if ( // check to see if we can switch to a new target alwaysSelectMaxConfidenceTarget && infoFightable.SuspicionFirm > ai.InfoCurrentTarget.SuspicionFirm && Time.time - targetChangedAt > targetSwitchMinInterval && ai.InfoCurrentTarget.transform != infoFightable.transform && infoFightable.lastKnownPosition.Confidence > 0 && infoFightable.health.Value > 0 && infoFightable.HaveFirePosition ) { ai.InfoCurrentTarget = infoFightable; needToReplan = true; needToReevaluateGoals = true; targetChangedAt = Time.time; } } } }
public override bool IsApplicapable(AIBrain ai) { bool canApplyToBlackboard = ai.HaveCurrentTarget(); return(canApplyToBlackboard && ai.WorldState.CompareKey(DS.haveTarget, true)); }
private bool FindSafePositions(AIBrain ai) { if (!ai.HaveCurrentTarget()) { return(false); } Transform transform = ai.Transform; List <Vector3> samplePositions = new List <Vector3>(); samplePositions.Clear(); float randDirAngle = Random.Range(0, 360); for (int randAngleCounter = 0; randAngleCounter < angleCheckCount; randAngleCounter++) { randDirAngle += 360 / angleCheckCount; float randStartDist = Random.Range(randomStartDistance.x, randomStartDistance.y); Vector3 startPos = transform.position + Quaternion.Euler(0, randDirAngle, 0) * transform.forward * randStartDist; Vector3 startDir = Quaternion.Euler(0, randDirAngle, 0) * transform.forward * Random.Range(randomStartDistance.x, randomStartDistance.y); NavMeshHit hit; Vector3 lastPoint = transform.position; for (int t = 0; t < checkAlongAngleCount; t++) { startPos = startPos + startDir * t * stepSize; startDir = (startPos - lastPoint).normalized; if (NavMesh.SamplePosition(startPos, out hit, 10f, NavMesh.AllAreas)) { samplePositions.Add(hit.position); #if UNITY_EDITOR if (showShapes) { Debug.DrawRay(hit.position, Vector3.up * 1f, Color.black); } #endif } lastPoint = hit.position; } } #region Check For Safe Position if (ai.InfoCurrentTarget.transform) { List <InformationSafePosition> infos = new List <InformationSafePosition>(); rayCheckCountVertical = rayCheckCountVertical <= 0 ? 1 : rayCheckCountVertical; maxDistanceFromTargetForMaxConfidence = maxDistanceFromTargetForMaxConfidence <= 0 ? 1 : maxDistanceFromTargetForMaxConfidence; float yStep = (rayHeightMinMaxVertical.y - rayHeightMinMaxVertical.x) / (rayCheckCountVertical - 1); for (int i = 0; i < samplePositions.Count; i++) { // Vertical Rays Vector3 samplePosition = samplePositions[i]; int rayHitToSafeCount = 0; for (int j = 0; j < rayCheckCountVertical; j++) { float height = rayHeightMinMaxVertical.x + j * yStep; RaycastHit hit; #if UNITY_EDITOR if (showShapes) { Debug.DrawLine(samplePosition + Vector3.up * height, ai.GetCurrentTargetPos() + Vector3.up * rayToTargetHeight, Color.red); Debug.DrawRay(ai.GetCurrentTargetPos() + Vector3.up * rayToTargetHeight, Vector3.up * 15f, Color.gray); } #endif if (Physics.Linecast(samplePosition + Vector3.up * height, ai.GetCurrentTargetPos() + Vector3.up * rayToTargetHeight, out hit, lineCastMask)) { if (!Checkers.IsOneOfTags(hit.transform, fightableTags) && !Checkers.isChildOf(hit.transform, ai.Transform.GetComponentsInChildren <Transform>()) && hit.transform != transform) { rayHitToSafeCount++; } } } if (rayHitToSafeCount >= 1) { float distFromSelf = Vector3.Distance(ai.Transform.position, samplePosition); float distSelfConf = 1 - Mathf.Clamp01(distFromSelf / maxDistanceFromSelfForMinConfidence); float distFromTarget = Vector3.Distance(ai.GetCurrentTargetPos(), samplePosition); float distTargetConf = Mathf.Clamp01(distFromTarget / maxDistanceFromTargetForMaxConfidence); InformationSafePosition infoSafePos = new InformationSafePosition ( samplePosition, (rayHitToSafeCount / (float)rayCheckCountVertical), distFromSelf, distSelfConf, distFromTarget, distTargetConf ); infos.Add(infoSafePos); } } infos = infos.OrderByDescending(x => x.OverallConfidence).ToList(); for (int i = 0; i < infos.Count && i < maxMemoryAddPerUpdate; i++) { ai.Memory.Add(infos[i]); } } #endregion Check For Safe Position return(true); }
public override bool IsStillValid(AIBrain ai) { return(ai.HaveCurrentTarget()); }
public override bool CanBeAddedToPlan(AIBrain ai) { return(ai.HaveCurrentTarget()); }
public override bool CanActivate(AIBrain ai) { return(ai.HaveCurrentTarget() && ai.GetSensor <SensorCanFireNMPositionFinder>().RequestInfo(ai) != null); }