Best way to lerp a model

I’m working on a knife throw for my game, however since the knife is made up of multiple meshes, I used a model and :PivotTo to change the CFrame for the throwing animation.

Here is the code

while (primaryPart.CFrame.p - final).magnitude > 4.5 do
		throwingKnife:PivotTo(throwingKnife.Handle.CFrame:Lerp(
CFrame.new(throwingKnife.Handle.Position + unit * 4.5, final) * 
CFrame.Angles(math.rad(-30), 0, 0), 0.5))

		-- throwingKnife.Handle.Position + unit * 4.5, final
		local magnitude = (primaryPart.CFrame.p - final).magnitude
		if previousPosition and previousPosition  < magnitude then
			break
		end
		previousPosition = magnitude
		heartbeat:wait()
	end

The Issue:

The code partially works, the knife reaches the destination however the Orientation never changes making it not rotate while flying. Am I doing something wrong here?

1 Like

just add a rotation variable:

local rotation=-30
while (primaryPart.CFrame.p - final).magnitude > 4.5 do
		throwingKnife:PivotTo(throwingKnife.Handle.CFrame:Lerp(
CFrame.new(throwingKnife.Handle.Position + unit * 4.5, final) * 
CFrame.Angles(math.rad(rotation), 0, 0), 0.5))

		-- throwingKnife.Handle.Position + unit * 4.5, final
		local magnitude = (primaryPart.CFrame.p - final).magnitude
		if previousPosition and previousPosition  < magnitude then
			break
		end
rotation+=30
		previousPosition = magnitude
		heartbeat:wait()
	end
1 Like

Yoo thanks it worked, do you know why it didn’t work when I tried to do it as math.rad(-30)? Because of the Lerp?

1 Like

No, it’s because the math.rad(-30) changes the rotation constantly but the final rotation is always the same. You need to change the number inside ‘math.rad()’ to make it rotate.

1 Like

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