Knife throw rotation [SOLVED]

If the knife is only a visual effect, you should use RunService.RenderStepped, and only if the knife is actually on the screen.

Here’s a sample script you can place inside a random part in workspace to see work.

local part = script.Parent

local rotateSpeed = 3 -- the speed the part rotates (in rotations per second)

local tau = (2 * math.pi)
local rotation = (tau * rotateSpeed)

local RunService = game:GetService("RunService")

-- Anchor the part if it isn't already anchored
part.Anchored = true

-- Run our loop
RunService.Heartbeat:Connect(function(deltaTime: number) -- you should use RenderStepped instead of Heartbeat
	part.CFrame *= CFrame.Angles(0, 0, (rotation * deltaTime))
end)

Anyway, just create a new part and plop this script inside and you’re good to go.

This isn’t actually meant to solve your problem, I’m just providing sample code to show how you can make the knife rotate.

1 Like

I don’t think you guys understood what I wanted. Ill show an example without scripts right now.

1 Like

Oh. Just re-read your post. You can accomplish this using CFrame.lookAt

local knifePos = knifeClone:GetPivot().Position
knifeClone:PivotTo(CFrame.lookAt(knifePos, knifePos + Character:GetPivot().LookVector))

This will only make the knife look in the direction the torso is facing. If you want it to look in the direction the head is looking in you can use Character.Head:GetPivot().Position instead.

Also, you may have to rotate the lookAt CFrame by 90 or 180 degrees on one of it’s axis, depending on which face of the knife you want looking in the direction the character is looking.

1 Like

Nope. Still throws the knife in a really weird way. If you want I can show you the recording of it.

1 Like

Alright, now I’m kind of confused. I guess show the recording.

1 Like

Here it is.
robloxapp-20220502-2226009.wmv (778.9 KB)

1 Like

try converting it into mp4, because it makes us download the file

1 Like

That’s why I said this:

In this case it probably only needs to be rotated by 90 degrees on one axis, at least from what I saw.

local correctionRotation = CFrame.Angles(0,0(math.pi * 0.5)) -- math.pi/2 is 90 degrees

local knifePos = knifeClone:GetPivot().Position
local knifeFrame = CFrame.lookAt(knifePos, knifePos + Character:GetPivot().LookVector) * correctionRotation

knifeClone:PivotTo(knifeFrame)

You may have to change the axis (math.pi * 0.5) is on in the CFrame.Angles variable, but you should be able to get it with some experimentation. You may also need to negate (math.pi * 0.5) to get the result you’re looking for.

1 Like

Okay, I will try everything you said and tell you if it works.

1 Like

Sorry to tell you but it still didn’t work. I tried experimenting but it still didn’t work. Maybe we could somehow get the direction the character is looking at and send the knife to that direction? Just saying. P.s I’m not good with rotating so I might not under some stuff you say.

1 Like

im not sure how your knife is rotated but based on the video it should be something like

knife.CFrame *= CFrame.Angles(math.rad(-90),math.rad(-90),0) --math.rad() is turning the degrees into radians.

if it doesn’t rotate how you want it just play around with it until you get it, because im terrible with xyz rotations

1 Like

Same I’m terrible with them aswell

1 Like

It just goes sideways when I try to throw from a different angle.

1 Like

robloxapp-20220502-2214045.wmv (3.6 MB)
This is how I want it to work.

1 Like

sorry for the late reply but its hard to tell if your code using position which im asuming it does so here.

knifeClone.CFrame = Character.HumanoidRootPartCFrame*CFrame.new(0,0,-1)*CFrame.Angles(math.rad(-90),math.rad(-90),0) -- teleports to the players rootparts coordinates moves it infront one stud and changes angles accordingly.

please remove

knifeClone.CFrame = CFrame.Angles(0,Character.PrimaryPart.Rotation.Y - Character.PrimaryPart.Rotation.Y % 90,Character.PrimaryPart.Rotation.Z)
	
knifeClone.Position = Character.PrimaryPart.Position

from your code and replace it with mine.

1 Like

Okay, I will try you’re code right now and tell you if it works.

1 Like

sorry i just realized i mistyped something

knifeClone.CFrame = Character.HumanoidRootPart.CFrame*CFrame.new(0,0,-1)*CFrame.Angles(math.rad(-90),math.rad(-90),0) -- teleports to the players rootparts coordinates moves it infront one stud and changes angles accordingly.
2 Likes

Its going backwards. I am not really a rotation guy so I don’t understand much sorry :frowning:

1 Like

its ok. its a simple fix then!

knifeClone.CFrame = Character.HumanoidRootPartCFrame*CFrame.new(0,0,-1)*CFrame.Angles(math.rad(-90),math.rad(90),0) -- teleports to the players rootparts coordinates moves it infront one stud and changes angles accordingly.

try that.

2 Likes

And no the knife still goes backwards :frowning:

1 Like