Quantcast
Channel: Latest Questions by Fox-Handler
Viewing all articles
Browse latest Browse all 90

Smarter AI Searching for the Player

$
0
0
I've been trying to set up the enemy Ai to take the player's last known direction and use that for a way to check specific waypoints in the level depending on what that last direction was. Does anyone have experience with enemy AI searching for the player? void Chasing () { // Create a vector from the enemy to the last sighting of the player. Vector3 sightingDeltaPos = enemySight.personalLastSighting - transform.position; // If the the last personal sighting of the player is not close... if(sightingDeltaPos.sqrMagnitude > 4f) // ... set the destination for the NavMeshAgent to the last personal sighting of the player. nav.destination = enemySight.personalLastSighting; Quaternion rotation = Quaternion.LookRotation(enemySight.personalLastSighting); if(nav.remainingDistance < nav.stoppingDistance) { //?????? } if(lastPlayerSighting.position != lastPlayerSighting.resetPosition) // if the alarm goes off then chaseSpeed { nav.speed = chaseSpeed; } else if(lastPlayerSighting.position == lastPlayerSighting.resetPosition) //if the alarm doesn't go off then alertSpeed { nav.speed = alertSpeed; } // If near the last personal sighting... if(nav.remainingDistance < nav.stoppingDistance) { // ... increment the timer. chaseTimer += Time.deltaTime; // If the timer exceeds the wait time... if(chaseTimer >= chaseWaitTime) { // ... reset last global sighting, the last personal sighting and the timer. lastPlayerSighting.position = lastPlayerSighting.resetPosition; enemySight.personalLastSighting = lastPlayerSighting.resetPosition; chaseTimer = 0f; } } else // If not near the last sighting personal sighting of the player, reset the timer. chaseTimer = 0f; }

Viewing all articles
Browse latest Browse all 90

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>