Oh, you meant like NPCs driving cars… Yikes, that’s a tough one. I may have a few solutions though.
You could have cars CFrame to areas right in-front of traffic lights/stop signs and you can tween cars toward them, once completed check if the stop light is green, if it is, do another tween, if not, wait until it is green, same goes for stop signs.
I am not certain on this next one, but RocketPropulsion may be feasible if you modify it heavily.
Or you could use a mix of both pathfinding, tweenservice, etc. I recommend doing a little more research upon it before deciding though.
You should use Steering Behaviors to simulate traffic.
Steering behaviors are used to move autonomous characters/vehicles in a natural manner. Wander steering and object avoidance steering behaviors are perfect! It takes a bit of math and physics though.
I have made a tutorial for the same. I also recommend to watch a few videos and read the official research paper, found here:
This would take a lot of work to turn into an AI Traffic system, I don’t anything too crazy. Just something simple for the time being because I need something asap.
Well, AI itself isn’t just what schools teach you, “Artificial intelligence”. So its probably going to take you months to achieve what you want. Good luck
Using steering behaviors on Roblox’ endorsed vehicles (because of their constraints & it’s built up with parts, instead of one mesh), I achieved into making pursuing cars & tactics within a few months. This can be changed to a traffic system with nodes too.
It needs motivation and experience, but it is definitely achievable on Roblox.
It’s not really that hard, because I (an intermediate scripter) managed to make them. I used TweenService as the fundamental part of the system.
The basis of the system is that cars drive from intersection to intersection. Cars also are assigned random IDs when they spawn, so that scripts can communicate to one specific car. (for example to permit it to proceed at an intersection).
At the intersection shown in the video (a 4-way stop), I used a table to determine which car should go first.
There was no pathfinding involved, instead I just randomised the direction they’ll take at the next intersection. To make the cars turn, I generated a Bezier Curve between 2 nodes, and made them tween along the curve with a loop. Here’s a video of my prototype system (which is currently being rewritten for better optimization). ROBLOX | AI traffic | 4-way stop demo #1 - YouTube
I looked up a bezier curve function on this forum and modified it for my use.
Since I do not plan on using that anymore in my current system, here it is:
--Functions
function lerp(a, b, c)
return a + (b - a) * c
end
function quadBezier(t, p0, p1, p2)
local l1 = lerp(p0, p1, t)
local l2 = lerp(p1, p2, t)
local quad = lerp(l1, l2, t)
return quad
end
--Curve generation script
for t = 0, 1, 0.011 do
local pos = quadBezier(t, workspace.Placeholders.SouthStart.Position,workspace.Placeholders.BottomRightTurnCenter.Position, workspace.Placeholders.SouthTurn.Position)
local newpoint = Instance.new("Part")
newpoint.Anchored = true
newpoint.Parent = script.Parent.Points
newpoint.Position = pos
script.Parent.OrientationValue.Value = script.Parent.OrientationValue.Value - Vector3.new(0,1,0)
newpoint.Orientation = script.Parent.OrientationValue.Value
newpoint.Transparency = 1
newpoint.CanCollide = false
end
Not really, the AI traffic I am working on is purely to make the game more lively. The direction they will take at the next intersection is randomised on spawn and per each intersection they pass through.
wow, now thats more like it thanks! Question tho, I already studied how roblox’s endorsed model car chassis thanks to your police AI post, i learnt how the car’s steering and propulsion functions work. I just wanna know this:
How do you calculate the steering angle?
To me this is useful if i want to make a free roam game. Roblox games need more ais than usual. But right now its just a project i wanna do.
In my current system, at curves, I merely set the car’s orientation to the curve part’s orientation, with Vector3:Dot() to make sure the car points in the right direction. It’s not the best implementation (as it “teleports” between orientations), but is a lot better than overcomplicating it with sensors at every curve.
At junctions, I have sensors with an “end angle” value in them. When a car hits that sensor, it’ll keep steering until the desired angle is reached.
Not really. I only used the Dot product to determine whether to use a negative degree or a positive degree for the orientation. You don’t actually need to use it in your system, it’s up to you how you design it.
Because why not? It’s actually legal in America atleast to proceed at the same time as someone else if you’re not cutting across their path. You are referring to my older video, right?
To elaborate on what trtman33 mentioned, an A* Pathfinder is a popular choice for that. You could use tyridge’s NodeGraph plugin or sleitnick’s Node Map.
Using one of these plugins, you can draw a nodegraph on your map. This is the road your car can drive on. For example, this is what an intersection could look like:
When your car is at the house, you can use the pathfinder module from your plugin to get a list of nodes between the house — store.
Drive to the first node in the list. Whenever your car is less than, let’s say, 20 studs away, you drive to the next node in the list. And that basically repeats till you reach your destination.
When you got that done, you can play around with the 20 studs range. Smaller ranges result into a more rigid path following, while wider allows more shortcuts. You can even make this dynamic, for example based on velocity! (Faster the vehicle is, the less shortcuts it’s allowed to take)