Devblog
3-point turns

3-point turns

Working on the car AI has been more enjoyable than I thought. I was driving in my car today and could not stop thinking about how the car in my game needs to “think” in order to get from place to another faster.

today I completely rewrote the code for reversing the car. It actually turned out pretty good and it can easily exit even harder locations.

The pre-made car AI asset I purchased (for 12 bucks) turned out to be pretty poorly done. It was ok for making laps on a racetrack. But using it to drive a car from a parking lot to a parking lot in a realistic environment with dead ends and such just turned out to be horrible. The car sometimes eventually got to it’s destination, but it took a while and it looked like the driver had no idea what he was doing.

Eventually I figured I would add some banter for him. Him muttering aloud how he has never before driven the stick etc.. But I never had to go there as I started to understand the car AI code better and better. And today I completely rewrote the code for reversing the car. It actually turned out pretty good and it can easily exit even harder locations. The car can perform some pretty sweet Knight Rider moves and more elegant 3-point turns. It is always a bit of a surprise what it figures out to do.

A couple of minutes of my car driving itself around the Google maps data. The reversing and 3-point-turns code works better than I expected! My custom debugger is also seen here. I had to go trough a lot of hoops to get the editor and build car drive exactly the same.

The car still does not sample anything behind it when reversing, resulting in some pretty crazy situations, but I feel the I can get away without adding a code for the car to “see behind”.

Example path gameObject with some collider boxes

To help the car a little bit. I added functionality for setting the car max speed during its trip. This way I can make the car slow down before a tight turn is coming up, or speed up on long straights. It helped a lot. I also added support for per-trip group of colliders that get enabled when fast-traveling a certain route and get disabled afterwards. Just to help the car not get lost. As it is still pretty stupid! Having the car drive without fail from destination to destination is really important. As the car is driven by physics it can do some unexpected stuff. But for my use the car must be perfect and 100% reliable!

Surprisingly the most trouble I had making the pre-made assed work the same way in a game build than it does in editor. Working that out was greatly educational! As physics based code is very new to me (I have never done it before). I needed to add a lot of in-game debug text to see what the car was thinking at all times to figure out where it goes wrong.

There are still some issues where the car has nothing blocking its path, but takes forever to continue moving. This usually happens after a 3 point turn. There must be some “sweet-spot” where the Ai does not know wether to go forwards or backwards.

Also as a side-note,

using Google maps data for my prototyping allowed be to start developing the car in an actual location. Building the system in an empty environment would have just given me a car that would not have worked in the actual environment at all. Starting with a pretty good location made me face a lot of problems that I needed to solve for this to work. I feel that Google date has accelerated my project immeasurably!

New readers:

I am working on an adventure game with a pretty large, open location. I needed a fast travel solution, so I added a car that can be used to go from a point-of-interest to point-of-interest

Tags :

Leave a Reply

Your email address will not be published. Required fields are marked *