How do I get this to follow the track instead of going straight to the point?

Hello!
I am trying to make a basic system where they will be a plate that will follow a track around to different points. I am using Lerp and if I can I want to keep it that I am using Lerp if I can.
The cart/base is just going straight to the point and not following the track around it. This is probably a very easy fix but I am not sure how to do it as I have not found a lot of good lerp tutorials that I need to complete this task.

Code:

local movePart = script.Parent.TrackFollowPart

local point1 = script.Parent.Parent.Parent.point1


for i = 0, 1,.01 do
	wait()
	movePart.CFrame = movePart.CFrame:Lerp(point1.CFrame, i)
end

1 Like

You can use the MoveTo method of the PathfindingService to navigate a path between points on a track.
Here’s an example script that demonstrates how to use PathfindingService to move a character along a track:

-- Get the pathfinding service
local pathfindingService = game:GetService("PathfindingService")

-- Get the track
local track = -- Set to the track instance

-- Get the starting point and ending point on the track
local startPoint = track.StartPoint.Position
local endPoint = track.EndPoint.Position

-- Create a path between the two points on the track
local path = pathfindingService:CreatePath({
    AgentRadius = 2, -- Set to the size of the character
    StartPosition = startPoint,
    EndPosition = endPoint,
    PathPriority = Enum.PathPriority.High,
})

-- Move the character along the path
local humanoid = -- Set to the humanoid instance
path:MoveTo(humanoid.Parent.Head.Position)

This script gets the PathfindingService and the track, and then creates a path between the starting point and ending point on the track. It then moves the character along the path using the MoveTo method.

Hello!
Thank you for your response and help.
I will try this out and see if it works!

Thanks :slight_smile:

1 Like

No problem, I hope you achieve your goal!

1 Like