How can I make a vehicle realistic drive to a point in workspace.
Picture of my thinking:
(RED Part = point)
I’ve been trying everything and cant get it to move.
How can I make a vehicle realistic drive to a point in workspace.
Picture of my thinking:
(RED Part = point)
I’ve been trying everything and cant get it to move.
Can you provide a example code so I can get a idea?
From Roblox:
local PathfindingService = game:GetService("PathfindingService")
-- Variables for the zombie, its humanoid, and destination
local zombie = game.Workspace.Zombie
local humanoid = zombie.Humanoid
local destination = game.Workspace.PinkFlag
-- Create the path object
local path = PathfindingService:CreatePath()
-- Variables to store waypoints table and zombie's current waypoint
local waypoints
local currentWaypointIndex
local function followPath(destinationObject)
-- Compute and check the path
path:ComputeAsync(zombie.HumanoidRootPart.Position, destinationObject.PrimaryPart.Position)
-- Empty waypoints table after each new path computation
waypoints = {}
if path.Status == Enum.PathStatus.Success then
-- Get the path waypoints and start zombie walking
waypoints = path:GetWaypoints()
-- Move to first waypoint
currentWaypointIndex = 1
humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
else
-- Error (path not found); stop humanoid
humanoid:MoveTo(zombie.HumanoidRootPart.Position)
end
end
local function onWaypointReached(reached)
if reached and currentWaypointIndex < #waypoints then
currentWaypointIndex = currentWaypointIndex + 1
humanoid:MoveTo(waypoints[currentWaypointIndex].Position)
end
end
local function onPathBlocked(blockedWaypointIndex)
-- Check if the obstacle is further down the path
if blockedWaypointIndex > currentWaypointIndex then
-- Call function to re-compute the path
followPath(destination)
end
end
-- Connect 'Blocked' event to the 'onPathBlocked' function
path.Blocked:Connect(onPathBlocked)
Really confused on this, I’m trying to make a vehicle model move to a position not a npc.
You can apply the same principles to it
you cannot use pathfinding api on a vehicle. Only on Humanoids
You can add a Humanoid to the vehicle.
Here are suggestion you can do
It would be illogical to do so
He does not want it to be like that. Im assuming he does not want the car to go to each point and then rotate and go onto the next point. He wants a smooth transition from one point to another without making it look choppy.
wouldn’t use physics then? unless that is fine with him
Wait, is lerping CFrame physics?
How do I make it lerp there realistically?
Honestly, it’s just a bunch of tweaking.
(Writing the code, one second).
I never used lerp and I’m confused on how to do this.
Sorry for the delay, this is how you would do it:
This Script is in ServerScriptService.
local ReferencePart = workspace:WaitForChild("Part")
local Car = workspace:WaitForChild("car")
for i = 0, 1, .01 do
wait()
Car.CFrame = Car.CFrame:Lerp(ReferencePart.CFrame, i)
end
What it should look like:
https://gyazo.com/55ea9e75f30ba42378048c5d790291b5
(Note: my studio is a little buggy right now, so it may look glitchy).
Oh sorry I meant wouldn't use physics?
Oh yeah, it would not use physics.