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?
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
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.