A good vehicle AI?

Hey guys, does anyone have a good vehicle AI? Preferably one that uses vehicle seats and doesn’t chase the player around, killing them with a death brick on the front of the car? Thanks! I’m looking for some police cars sorta like GTA so that’d be great. Thanks! We need some kind of API for this…

11 Likes

Never created any AI, but my Opinion is that u will need to Create a Pathfind first, the problem is that pathfind only supports small model such as humanoid model. By that u need to add several raycast going through directions, to detect whenever the car is near something.

5 Likes

Heres an experiment you can try…

Make a clone of of just your roads and put them say 200 studs off the ground. Run all of your pathfinding stuff up there in the clouds. Check the angle between the points every three studs or so and it the angle is getting close to 90 deg then push out the middle point closer to the center of the road so the cars don’t hit corners of buildings

You will start to run into problems if you use more than one car though. Or if you plan on having a lot of things on the road

Lmk how it goes

2 Likes

Instead of using raycasts and such which would have a time complexity of the number of vehicles you have moving around and the number of raycasts performed by each vehicle being computed in the instance, you could probably look into dijkstra’s algorithm which may be the best way to compute paths similar to the way GTA does.

I’m not sure how their AI works but it can’t be far from using methods like that.

3 Likes

Like above, you could use raycasting on each side of the vehicle, then for example say if there is a car stopping in front, you could stop so many studs behind that car.

1 Like

Yeah using raycasts would be one of the better ways handling detection. In fact, in a sense, it’s what the modern day cars with autopilot systems do

3 Likes

A* (Astar) is an adaption of Dijkstra’s algorithm optimized for games and real-time processes like robotics.

6 Likes

This is more or less just collision avoidance rather than an AI trained to navigate to a location. Anyways I made this about a week or two ago and open sourced it if you would like to look at the code. However in my opinion if you want to make cars that navigate city roads in a semi-controlled environment like Roblox, I would recommend creating a custom Pathfinding system and just scripting it to navigate to those locations.

11 Likes

That might be the best AI car I’ve seen in roblox so far. Unfortunately, I, unlike most of you, am not super savvy when it comes to things like artificial intelligence. I think my best bet at this point would be A.) modifying the open source one provided above or B.) finding an alternative to AI cars. Thanks for the help! If anyone else is reading this thread, there’s a nice Free model AI car prototype I found, and it’s pretty simple and I assume easier to understand. I played around with that for a while and (sorta) began to understand the concepts about how it worked. It worked by having parts that collided and would steer away from the parts when they were touched. Unfortunately, I couldn’t use it because it doesn’t allow for ramps.

1 Like

That’s a really good AI, but for the topic ahead, I think you should either use player pathfinding scripts and import them into the vehicle or just use his AI like you said above me.

1 Like

I did make an AI that would follow traffic lights, turns, etc, but I dropped it as I got sick and tired because of the lack of functionality with being able to script VehicleSeats. I doubt I still have the code anymore.

2 Likes

Interesting, I’ve never seen this demo but it might come in handy. Thanks for posting it here.

2 Likes

If it does intrest you, I used A* pathfinding with raycasting to prevent vehicles hitting others. If you do want a copy of the place, please let me know.
Game: Police - Demo - Roblox
EDIT: Place is uncopylocked, so you can take a copy if you want. Have fun!

21 Likes

Thank you so much sir i was looking for a good example on how a star would work and as i realise and as i look i think to myself why i didnt think of that A* is a weird topic for me i have mastered other topics for lua and have made other custom alogrthitims for pathfinding but never found out how to do it in a way that the source engine would do it thank you man!