I have enemy AI cars chasing the player car on a system of roads using waypoints/point graph. It’s working really well and I started implementing a vision system for the enemy cars.
Basically, the idea is that when the enemy car looses sight of the player it should still continue driving (assuming, like a human would do, that the player is still driving further down the road) until it reaches an intersection.
If the enemy car reaches an intersection and still doesn’t “see” the player car, then the chase is over, and it drives to another random intersection - and so forth.
Basically, I would need to switch the target position from player car to the closest intersection in the direction the enemy car is driving. Finding the closest object tagged “intersection” would work but I can’t figure out how to make sure it’s in the driving direction and on the same road.
Is there a way to “project” a path in front of the enemy car until it reaches an intersection node and make it the target?
Or some other way of achieving this?
public void Move(Transform Target){
if(this.position == Target && CanSee != true){
chasing == false;
// If chasing == false the car will exit at the next intersection~
}
else{
chasing == true;
}
}
`
Thank you for your help Burdock. I already implemented a “lastSeen” location based on raycast - so the target switches from playerCar to lastSeen.transform.position. The problem comes afterwards.
Imagine you are following a car and lose sight of it. You wouldn’t just drive to the last location you’ve seen the car but rather to the next intersection, in hope that you can catch up and/or see the car again (also, my game takes place in a rural environment, so the next intersection can be kilometers away).
I basically need to extend the A* path from AIcar-lastSeen to AIcar-lastSeen-nextIntersection and I can’t use findClosest because the closest intersection could be behind the car. It has to be the closest intersection ahead.
Another idea would be to search for closest intersection, calculate a path to it and if the nextWaypoint is behind the car, cancel the path, search for the second closest intersection, calculate a path… and so forth, until the nextWaypoint is in fron of the car. But that’s a very clumsy way to do it.
My main, path specific question still remains: since I have a path from AIcar to lastSeenPosition, is it possible to extend that path until it reaches a node tagged “intersection”?