Troubles With Lerps

I made a for loop that creates a part for every increment of a lerp, from one node to another.
However, the parts seem mostly skewed towards both the current node and next node.

image

you might not be able to see it but there’s a lot of parts stacked on each node, meanwhile the middle has barely any parts

this is a portion of my script that does one loop from one node the to the next.

local Position = CFrame.new(game.Workspace.Start.Position)
local Nodes = game:GetService("Workspace").Nodes
local Magnitude = (Nodes:FindFirstChild(tostring(CurrentNode)).Position-Nodes:FindFirstChild(tostring(CurrentNode+1)).Position).Magnitude
--just the distance from node to next node
local Speed = Enemy.Speed
--it's 10

		for i = 1, 20 do
			Position = Position:Lerp(game:GetService("Workspace").Nodes:FindFirstChild(tostring(CurrentNode+1)).CFrame, i/20)
			local part = Instance.new("Part")
			part.Anchored = true
			part.Size = Vector3.new(1,1,1)
			part.Parent = game.Workspace
			part.CFrame = Position
				
			task.wait((Magnitude/Speed)/20)
		end

Is there any explanation for why the parts seem so skewed?
my guess is that it has something to do with cframe but i’m not sure

It because you are taking a percentage of a percentage.

The correct way would be to

Position = StartPosition:Lerp(EndPosition, i/20) --i/20 already described linear movement
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.