Part positioning at wrong place

So i am using lerps to show trajectory of a projectile with trail, creating almost perfect bullet trail. But for some reason, projectile with the trail spawns somewhere else then its supposed to. Here’s a video of the trail starting basically in the middle of whole trajectory:


I have a starting part for the projectile wielded like this:
image
and this is my lerping script:

local function lerp(a,b,t)
	return a + (b-a) * t
end

local function linearLerp()
	local projectileC = projectile:Clone()
	projectileC.Anchored = true
	projectileC.CanCollide = false
	projectileC.CFrame = CFrame.new(firePart.Position)
	projectileC.Parent = workspace
	local start = firePart.Position
	for i = 0,6,1 do
		local t = i/6
		local linear = lerp(start,currentTarget.PrimaryPart.Position,t)
		projectileC.CFrame = CFrame.new(linear) 
		task.wait()
	end
	game:GetService("Debris"):AddItem(projectileC, 1)
end

Your code is skipping the initial position

it sets to start

	projectileC.CFrame = CFrame.new(firePart.Position)
	projectileC.CFrame = CFrame.new(linear) 

Then it immediately sets it 1/6 of the lerp in

Add another wait

local function linearLerp()
	local projectileC = projectile:Clone()
	projectileC.Anchored = true
	projectileC.CanCollide = false
	projectileC.CFrame = CFrame.new(firePart.Position)
	projectileC.Parent = workspace
	local start = firePart.Position
task.wait()
	for i = 0,6,1 do
		local t = i/6
		local linear = lerp(start,currentTarget.PrimaryPart.Position,t)
		projectileC.CFrame = CFrame.new(linear) 
		task.wait()
	end
	game:GetService("Debris"):AddItem(projectileC, 1)
end

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