/// <inheritdoc/> public override void Update() { //CheckVision AISensors.VisionResult visionResult = entity.Sensors.CheckVision(); if (visionResult.fearPoint != null) { AIUtils.InitiateFear(entity, visionResult.fearPoint); } if (entity.InFear) { entity.Data.fearTimer -= Time.deltaTime; } if (!entity.InFear) { if (visionResult.playerVisible) { if (Vector3.Distance(entity.transform.position, Player.Instance.transform.position) <= 0.9f) { controller?.SpotPlayer(); } //Move to last seen position controller?.MoveTo(entity.Data.lastSeenPlayerPosition); //Spot with outer vision and reset timers if (visionResult.sensorType == AISensors.SensorType.Outer) { entity.Data.currentAttentionPlayerSpotWaitTime = entity.Data.AttentionPlayerSpotWaitTime; entity.Data.currentAttentionWaitTime = entity.Data.AttentionWaitTime; } //Spot with inner vision and switch to aggression if timer is up else if (visionResult.sensorType == AISensors.SensorType.Inner) { entity.Data.currentAttentionPlayerSpotWaitTime -= Time.deltaTime; if (entity.Data.currentAttentionPlayerSpotWaitTime <= 0) { controller?.SpotPlayer(); } } entity.Data.lastSeenPlayerPosition = Player.Instance.transform.position; } //Relax if player not seen else { //Move to last seen position with rand position controller?.MoveTo(entity.Data.lastSeenPlayerPosition + walkRand.randPos); walkRand.DoAction(); entity.Data.currentAttentionPlayerSpotWaitTime = entity.Data.AttentionPlayerSpotWaitTime; entity.Data.currentAttentionWaitTime -= Time.deltaTime; if (entity.Data.currentAttentionWaitTime <= 0) { controller?.Relax(); } } } }
/// <inheritdoc/> public override void Update() { base.Update(); AISensors.VisionResult visionResult = entity.Sensors.CheckVision(); if (visionResult.fearPoint != null) { AIUtils.InitiateFear(entity, visionResult.fearPoint); } if (entity.InFear) { entity.Data.fearTimer -= Time.deltaTime; } //Attack player if visible if (visionResult.playerVisible && Player.Instance != null) { entity.Data.currentAggresionWaitTime = entity.Data.AggresionWaitTime; try { entity.Data.lastSeenPlayerPosition = Player.Instance.transform.position; } catch { } entity.assignedZone.PropogatePlayerPosition(entity.Data.lastSeenPlayerPosition); if (!entity.InFear) { controller?.MoveTo(!weaponBehaviour.IsDistanceOptimal() ? entity.Data.lastSeenPlayerPosition : entity.transform.position, false); } weaponBehaviour.DoAction(); } //else move to last seen position else { if (!entity.InFear) { controller?.MoveTo(entity.Data.lastSeenPlayerPosition + walkRand.randPos); } walkRand.DoAction(); entity.Data.currentAggresionWaitTime -= Time.deltaTime; if (entity.Data.currentAggresionWaitTime <= 0) { controller?.Relax(); } } }
///<inheritdoc/> public override void Update() { //Check if player visible, and switch to attention state if so AISensors.VisionResult visionResult = entity.Sensors.CheckVision(); if (visionResult.playerVisible) { if (entity.Data.currentPlayerSpotWaitTime > 0) { entity.Data.currentPlayerSpotWaitTime -= Time.deltaTime; } else { entity.Data.lastSeenPlayerPosition = Player.Instance.transform.position; controller?.SwitchState(controller?.attentionState); return; } } else { if (entity.Data.currentPlayerSpotWaitTime < entity.Data.PlayerSpotWaitTime) { entity.Data.currentPlayerSpotWaitTime += Time.deltaTime; } } if (visionResult.attentionPoint != null) { entity.Attention(); entity.assignedZone.PropogatePlayerPosition(visionResult.attentionPoint.position); visionResult.attentionPoint.gameObject.SetActive(false); return; } if (visionResult.fearPoint != null) { AIUtils.InitiateFear(entity, visionResult.fearPoint); } if (!entity.InFear) { //Patrol routine if (entity.Data.Path != null) { //Select target point patrolPath = entity.Data.Path; if (targetPathNode == null) { targetPathNode = entity.Data.Path.Next(out AIPath newPath); if (newPath != null) { entity.Data.Path = newPath; } if (targetPathNode != null) { entity.Data.pointWaitTime = targetPathNode.WaitTime; } } else { //Movement to target point, stay and rotate towards point direction if wait time is > 0 controller?.MoveTo(targetPathNode.Pos); if (Vector3.Distance(entity.transform.position, targetPathNode.Pos) < 0.75f) { entity.Data.pointWaitTime -= Time.deltaTime; if (entity.Data.pointWaitTime > 0f) { controller?.RotateTo(targetPathNode.Dir); } else { targetPathNode = null; } } } } else { //Move to spawn point if no path controller?.MoveTo(entity.Data.spawnPoint); if (Vector3.Distance(entity.transform.position, entity.Data.spawnPoint) < 0.75f) { controller?.RotateTo(lastDir); } } } //Sleep routine entity.Data.waitForSleep -= Time.deltaTime; if (entity.Data.waitForSleep <= 0f) { controller?.Sleep(); } }