Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

is it possible to move a part to a location without the part slowing down?

When the Parent block moves closer to the Locations the block slows down as it gets closer, is there any way for this to work as constant speed?

If anything I'm pretty sure it's to do with the way I've lerp'd it but I'm honestly not too sure.

local self = script.Parent
local Folder = game.Workspace.Locations
self.Parent = game.Workspace.Enemies
local locations = {
	Folder.Location1,
	Folder.Location2,
	Folder.Location3,
	Folder.Location4,
	Folder.Location5,
	Folder.Location6,
	Folder.Location7,
	Folder.Location8,
	Folder.Location9
}


for i,v in pairs (locations) do
	local targetLocation = v
	while((self.Position-targetLocation.Position).magnitude >= 0) and wait() do
		self.CFrame = self.CFrame:lerp(targetLocation.CFrame, 0.01)
		self.CFrame = CFrame.new(self.CFrame.p, targetLocation.CFrame.p)
	end
end

1 answer

✓ Accepted answer

Common problem in this line: self.CFrame = self.CFrame:lerp(targetLocation.CFrame, 0.01)

If 0.01 were 0.5 you can imagine like on a linear race track, each frame the runner cuts his distance to the finish line in half. At first he clears half the distance but eventually barely moves because there is no distance to cut.

Basically you want to lerp an old cframe, not the new ones. Only change the distance to move.

for i,v in pairs (locations) do
    local targetLocation = v
    local old = self.CFrame
    local i = 0
    while((self.Position-targetLocation.Position).magnitude >= 0) and wait() do
	i=i+1
        self.CFrame = old:lerp(targetLocation.CFrame, 0.01*i)
        self.CFrame = CFrame.new(self.CFrame.p, targetLocation.CFrame.p)
    end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.