You are browsing as a guest. Sign up (or log in) to start making projects!

Open comments for this post

4h 35m 45s logged

I have been working on making racing ai for the game. As a small intro, i have worked on this project before, and what I got is a working car controller, and dialed in physics to something I like how it feels.

The ai represented a difficult problem. If I want this to be open world, and for there to be police chases, I needed the NPC car to be able to go offroad, so basically, of a set path. There would be the option to make a hand tailored map and even for the offroad sections to be counted as roads, but that would be hard for one developer to do and test, so I opted for this. When the car is not on a road network, it fallbacks to the built in navmesh system in unity. It then uses it to calculate a path as a list of point and then drives between them. On the road, we just need to sample points from the spline of the road and then drive between them.

The hard part was this driving part :D
While it might seem simple, just point the car to the next point, and then have it move forwards, there is much more nuance to this. First, the NPC car should behave just like the player car, it should have the same turn angle, and thus I must now convert a simple direction into a steering angle. Another difficult part is when racing. I can’t just have it accelerate always, the car must brake when a sharp corner is coming up, and for really tight one, maybe even drift. So how do you do that? Well, i dont know yet, this past 4 hours I have been working on the same script and same section trying to figure that out. I really hope that next devlog I can come with a solution, but i cant promise anything.

My plan is to calculate the curve of the upcoming curve, and then somehow spit out a good speed for that, but there are a lot of factors to account for, like the grip of the car and actual speed, distance to corner etc.

0
1

Comments 0

No comments yet. Be the first!