How to make knife rotate in the air?

I am making a throwable knife and in my script I anchor the knife and then on every renderstepped I move the knife a little in the direction of the throw.

I want to get the knife to rotate while it is in the air.

The problem is that normal scripts don’t work and my knife goes crazy when I try to rotate it in my script.
Here is the code:

local Loop
local pos = getMousePos()
Loop = game:GetService("RunService").RenderStepped:Connect(function(dt)
    throwknife.CFrame = CFrame.new(throwknife.Position + throwknife.CFrame.lookVector, pos)
    local rayParams = RaycastParams.new()
    rayParams.FilterType = Enum.RaycastFilterType.Blacklist
    rayParams.FilterDescendantsInstances = {tool, player.Character or player.CharacterAdded:Wait()}
    local raycast = workspace:Raycast(throwknife.Position, throwknife.CFrame.lookVector, rayParams)
    if raycast then
        local hit = raycast.Instance
        local normal = raycast.Normal
	    local pos = raycast.Position
        print(hit.Name)
	    Loop:Disconnect()
    end
end)

You may want to make a copy of knife instread of leaving it connected it with character by means of tool

I would cache the initial vector from the knife to the mouse pos, as when the knifes cframe changes when it rotates so does the look vector.

@primo222 yes I have actually cloned the knife and it throws, it just doesnt rotate

As post above says you need to replace look vector with mouse position at raycast and with multipling on rotated CFrame with minimal position at setting new CFrame

Okay, can you explain how I would do that?
So I can change the lookvector but how to rotate.
Can you please provide a code block?
thanks

I changed the lookVector to the mouse pos

I found this CFrame script that rotates like this:
image

Script:

while true do
	script.Parent.CFrame = script.Parent.CFrame * CFrame.fromEulerAnglesXYZ(0.00,0.09,0.0) * CFrame.new(0, 0, 0)
	wait(0.001)
end

You can find a way to change it to rotate in the way you desire.

1 Like