Chasing Vehicle AI

Trying to create chasing vehicle AI for example the AI vehicle has the ability to follow the players vehicle. The AI is created by blueprint using a AI controller. Currently the vehicle AI is following a spline road around a track. It can detect other vehicles in the world so its aware of other vehicles when in sight. I cant figure out the chase part of the blueprint.

Any advice would be greatly appreciate it

Hi, I’m afraid there’s is no node like Move To for the vehicle movement component and you would have to implement it on your own.

I can give you a high level abstraction of how I implemented it (completely in blueprints, cause I don’t know much about C++) but it will not be trivial to implement it:

Basically you use the “Find Path to Location Synchronously” node. This will give you the path points using the navmesh from a start location to the desired end location.

Then you use those locations and the wheeled vehicle movement input (so “Set Throttle Input”, “Set Steering Input”, “Set Handbrake Input”) to move to the target location (I let the vehicle move from one point in the path to the next one, until it reached the target point).
If you would want to move to a moving target, then you would create a timer and check whether this moving target has moved from it’s last location and if so, then update the path points, so call “Find Path to Location Synchronously” again with the new location.

Next thing is you would want to create a new nav agent with a bigger radius for the vehicle in the project settings, else your vehicle will try follow a wrong path/not find a path.
Further I used “RVOAvoidance” in the vehicle movement component, so that the vehicles don’t crash into each other. [HR][/HR]
I wrapped all the logic up to be called by a single event (I called them “Move To Location” and “Move To Actor”), and called that event then from a task of the behavior tree through an interface.
The steering input is fairly easy. You would get the vector from the vehicle to the current point (subtract both locations) and since you also know the direction the vehicle is facing, you can do a dot product of those two vectors and then you would know whether to steer left or right and how strong.

I made the throttle input depending on the steering input, so the stronger the vehicle is steering the lower the throttle input will be. Further I also did the dot product above not only for the current point, but also for the next point in line (to anticipate curves) and therefore sometimes corrected the throttle input downwards (else the vehicle might overshoot in a curve).

Hey thanks for the response. Currently my AI vehicle detects the spline for the racetrack and follows it so that’s all set up. What I’m looking to do now is have the AI vehicle following my car think of car chases/cop chases so high speed chasing. Would this be possible to do in blueprint. C++ I have never used it before.

So I did my vehicle movement (the one I described above) completely in blueprints :slight_smile:

But I made the movement based on the navmesh (so the vehicle can move everywhere in the navmesh is) not splines and not for a race game but a multiplayer shooter where I wanted AI vehicles.
So if I understand your setup right, then the player and the AI can only move along streets. Further you have a spline for each street lane and the AI follows this spline to move.

(1) So for close up movement I would do something like this:
I would do a dot product between the normalized vector from the AI to the player with the tangent of the spline at the position the AI is currently located. If the dot product is positive, it means the player is in the direction of the tangent of the spline and your AI should move that way.
If the dot product is negative, it means the AI needs to move in the opposite direction of the spline tangent.
You could then further compare the direction the player is in with the direction your AI is already moving and slow down/ change direction if necessary.

But this only works for short distances or if your street is fairly straight, so has no loops Imagine you would have a U turn, there it would fail if the bot is one one side of the turn and the player on the opposite cause this system would tell the AI to turn around (because the player moves in the opposite direction of the AI) although the right decision would be to keep direction.

(2) For longer distances especially if your streets can split up you would need a different pathfinding system, something where you input the player location and it will then output a list of splines the AI needs to follow to get to the player and when the AI gets close to the player, switch systems. [HR][/HR]
Said all that I think for long distance, so for (2), I would use navmesh movement instead of spline movement and limit the navmesh for this AI agent to the streets only and when you get close you may want to switch to (1).

Thanks for your help sounds good, That’s correct the player and the AI can move along streets long distance AI follows this spline to move.
I can join alot of splines together as one but there is intersection which is a different spline. The splines have loops I have added a curve anticipation so the AI can handle turns well.