CFrame:lerp() slows down as it reaches goal CFrame

I’m currently trying to develop a tracer system, and so far, it’s working quite well - until you shoot at something that’s close - or it’s nearing it’s destination.

I’m not sure what to do, but here is my code:

for i = 0.2, 1, 1/60 do 	
fakeBullet.CFrame = fakeBullet.CFrame:lerp(conversion, i)	
wait(0)
end

4 Likes

You need to record the starting point before the loop and lerp that instead.

startpoint = fakeBullet.CFrame
for i = 0.2, 1, 1/60 do
fakeBullet.CFrame = startpoint:lerp(conversion, i)
wait(0)
end

What you are doing is (For sake of simplicity I will use halves) moving halfway to the target, then moving halfway again, and then halfway again.
If you start at 100 studs from your target, next step you are 50. Then the next you are 25. Then 12.
Because each iteration you are moving halfway from the current position to the target, and the current position changes each iteration.

9 Likes

Thanks!

That solved that issue - now I have another one.

If you fire close to an object, it’s still really, really slow (but doesn’t slow down as it nears said object!)

I’ve also never used lerps a lot, so it’s probably something I’m missing.

Using lerps with a static ‘alpha’ will always take the same amount of time regardless of distance.

You should probably use a different way to move the bullet. It depends on the rest of your system and what relies on it I suppose, but there are a couple of ways you can do it.

If you absolutely need to use lerping, you can change the amount of iterations like so.
step = 1/60
startpoint = fakeBullet.CFrame
for i = step, 1, 1/step do
fakeBullet.CFrame = startpoint:lerp(conversion, i)
wait(0)
end

And then set ‘step’ dynamically based on the distance of the shot. That’s not really the best way of doing it, but I am just throwing this out there so you know it is an option.

1 Like

I might just make it so the bullet CFrames itself to the hit location, without Tween.

The guns themselves are hitscan, I just need a way to visualize the trajectory so other players know that someone is shooting at them - plus, it’s a cool effect.