This post is going to be a bit more technical than previous posts as we discuss the process behind creating the driving behaviour of the enemy vehicles and some quirks about the Unity3D engine. Minor knowledge about vector math is required to fully understand everything but it should be mostly understandable without it. I am going to refer to vehicles in general while meaning vehicles moving on land which move roughly in the same way as cars.
But before moving on to how the behaviour works, what is its purpose and what requirements are placed on it? Firstly it has to move the vehicle to be in the proximity of the player. Secondly it has to drive the vehicle in a somewhat believable way, meaning that the vehicle should not move sideways or in other obvious non-vehicle directions. Finally, I wanted to avoid using Unity’s wheel colliders as they can cause a lot of problems.
From this we see that we need some kind of path finding to get to the player as there will be obstacles in the level. The first thing that crossed my mind was to use Unity’s built in NavMesh and NavMeshAgents to control the movement. However, it quickly dawned on me that the navmesh system wouldn’t be as perfect as first believed.