Vehicle Pathfinding?

I am still very confused on how I would be able to achieve the car movement that Cities: Skylines uses. If you haven’t played Cities Skylines before then here is an example of what I’m trying to achieve. The Most Cars I've EVER seen in Cities Skylines! - YouTube 1:18 - 1:25. How would I be able to set up a road or highway and have the cars drive on it correctly.

I’ve tried pathfinding, raycasting, and even tried detecting other objects around the car but I still cannot figure out how to achieve my goal.

so basically what you want is to tween the cars along some premade path, that you can customize as a player, right?

Yes, I’m trying to make a game similar to Cities: Skylines. Where you can place the road to a highway and eventually a car gets on it. I just do not know how I would manage to make a car do that.

I have an idea. Why don’t you make an invisible part for the car to follow, and tween the part along the road. That should solve the angle problems. I’m making right now an example.

Right now I’m just setting up a brick as my car. I’m going to try your idea but I’m still a bit confused on what you mean.

i’m trying to do my idea too and see how it behaves :slight_smile:

1 Like

you need PathfindingService something like this (im not the best at coding)

local PathfindingService = game:GetService(“PathfindingService”)

a nuther way is using conveyors and welding
this will take longer though

Some roads will have lanes so I’m not sure if that will work. Pathfinding will just make the car move directly to the point without moving on the road. Using conveyors I’m not sure if I could do that either.

1.you take a car from toolbox or custom made
2. unanchor the car so it can move freely
3. get a conveyor from the toolbox or custom made
4. weld it to the car
5.add BodyAngularVelocity
6.set the volicity to a VERY high number Dont do infinity
7.Run the game to see if it works

it does not reqire a lot of scripting but its basically a trial and error

@TwoSereneSticksII I dont really know how to move cars but it must have a humanoid root part or something like that

@TwoSereneSticksII i made it, finnally.

https://gyazo.com/505bde09caed9b98d302df274cf46285

and the script:

local car = script.Parent
local goal = car.Parent.Goal
local IdealCframe = CFrame.new(car.Position, goal.Position)
local distanceGoal_Car = (car.Position-goal.Position).magnitude
local Idealposition = IdealCframe.LookVector.Unit * (distanceGoal_Car - 5) --your offset so it doesn't bug out

local BF = Instance.new("BodyPosition")
BF.Position = Idealposition
BF.Parent = car

local BG = Instance.new("BodyGyro")
BG.CFrame = IdealCframe
BG.MaxTorque = Vector3.new(40000,40000,40000)
BG.Parent = car

local update = function()
    IdealCframe = CFrame.new(car.Position, goal.Position)
    distanceGoal_Car = (car.Position-goal.Position).magnitude
    Idealposition = car.Position + IdealCframe.LookVector.Unit * (distanceGoal_Car - 5)
    BF.Position = Idealposition
    BG.CFrame = IdealCframe
end

while true do
    wait()
    update()
end
2 Likes

now all you have to do is tween the Goal part along the roads and make a algorithm for every road bit, like curves and so on, to tween the goal part so it seems that the car is going on the road

1 Like

Ok, lemme break it down:

Make a small invisible brick. Make another long invisible one and use that as the path it will follow. Simply have the invisible brick follow that path. Then, take your car and position it on the lane. Use TweenService to move the car to the invisible part following the path. Do this for every lane.

4 Likes

Thanks for everyone’s help I think I got it now. This is very helpful. I think I’ve got everything else handled at this point

2 Likes