Agents Controlling a Vehicle

Hi guys,

I am using version 3.8.10 and I have used navmesh for all my levels.

i have setup a navmesh. then created a car with an Agent and car controller - the script that controls the car. The car controller takes in the path.vectorPath[currentWaypoint] and works out the angle to turn the steering wheels and orientate the car along the path. Sometimes the path recalculates before a vehicle has turned to face the right way but thats ok as there is a final destination for it to reach.

With the funnel modifier this works really well and the car will navigate over the course and goes along the path smoothly.

I am stuck with putting obstacles in front of the cars path, the pathfinding is correct and thinks the next waypoint is behind or through the obstacle so the agent is trying to get to the final destination. I can raycast infront of my car and detect an obstacle and tell the car controller to slow down and stop or reverse if its too close but the path recalculation usually determines that it should move through my obstacle again and my car goes into deadlock - unable to go forward too much or reverse back too much.

If i have an agent attached to a vehicle what is a good approach to implement obstacle avoidance ? Do i need to learn how to use the RVOAgent ? or can i move the currentWaypoint and force a recalculation of the path ? Has anyone used the agents like i have to be auto pilots of vehicles so they are confined to the movements of the vehicle and not an free moving things ?

What I think am asking is for a recommendation of an approach to path finding and obstacle avoidance - if agents are constrained to the controls of a simulated vehicle and is this a good idea ?

Thank you.


Are you creating a racing game or something similar?
If so I actually don’t recommend pathfinding at all because the obstacles are usually not complicated at all and some kind of steering behavior will work a lot better (see for example
Pathfinding for a racing game will not work well because it does not take into account the speed and direction of the car, so a reasonable pathfinding path might take the car backwards, but that will look very strange in a racing game.

1 Like

There is open terrain and the vehicles are moving across the terrain, I am dynamically adding buildings to the terrain and dynamically dropping targets for the vehicles so they act like they are patrolling. If a building is spawned in the path of a vehicle then it will stop it.


Ok, so then your question is about how to handle movement when your agent is constrained to vehicle-like movement (cannot turn too quickly) but the calculated path requires it to do this? Is that correct? that helped me out. Thanks :slight_smile:

@aron_granberg Hi, I was trying to find out if it was possible to handle a vehicle movement with A* Pathfinding Project and found that post. Could you please answer your own question? :slight_smile:

1 Like

Yes, I can use this too.

Hey guys the answer is in here

What I did was make a driver AI script that try’s to turn the vehicles wheels toward the next a* waypoint and it drives forward to the waypoint. As a fall back it casts sensors forward backwards and angled
Left and right.

If these sensors detect an obstacle the driver AI decides to stop following waypoints until it can navigate away from the obstacles by checking the sensors for contact. It turned out pretty awesome people say my AI is too deadly now.

Thanks. Did you manage to do reverse and turn radius etc…?

Yeah when the front sensor was triggered I reversed,

Or if moving forward if the left Sensor is triggered move right only. Etc

If back sensors where triggered move forward etc.

If no sensors turn stearing back to following a* to head toward path finding nodes.

So I used a* to plot the directions to a target position if a building or vehicle etc got in the way and triggered sensors the ai driver decides to stop following the a* nodes and freestyles his way out.

This system is pretty close to my ai driver he uses this to follow nodes or avoid sensors

Tel me how ya go

So the vehicle takes inputs like accelerate stearing etc
The ai driver is very much like the player script and it passes x, y floats to the stearing on the vehicle to turn etc. cause the player is now a scripted version, the ai driver, it needs to know about a* and it’s next waypoints etc. so it can calculate the angle needed to turn the stearing to direct the car to face the next node of A*. When it’s doing that the ai driver also reads sensors just like a player would and try’s to avoid obstacles as it try’s to follow the nodes to the next way point.

Thank for all the info!! I guess you’d be making “self driving car” on a small scale. I am trying to use this for wheeled and tracked (much easier since the turn radius can be high) and trying to figure out the best possible way to do this. The biggest challenge I see is when I have other vehicles and units (e.g. non vehicle types like soldiers) near by. Thanks again.