I’m working on a Murder Game, and I want to create a Knife similar to that of the “The Mad Murderer”. However I’ve been struggling with making the knife actually throw.
What I want
I simply just want to raycast to the target, and I want it to move towards it with the blade facing the target.
What I’ve tried
I’ve tried to come up with a solution, but I’ve come to no avail. I’ll show you want I’ve done.
-- Fired after the Player throws the knife, it is rendered clientside.
Event.OnClientEvent:Connect(PlayerThrowingIt, Target)
local Knife = PlayerThrowingIt.Character:WaitForChild("Knife")
local NewKnife = Knife:Clone()
Knife.Transparency = 1
while math.abs(NewKnife.Position.X) > Target do -- I had no idea how to get past here so I gave up. The position must be relative to the target and where the player is facing.
-- TODO: RenderStepped Wait
end
end)
If you look at the comments you can tell I have no idea what to do. Any help?
I make some minor edits, here’s the finished product:
local RunService = game:GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("ThrowEvent")
local Velocity = 30
Event.OnClientEvent:Connect(function(Player, Target)
local Knife = Player.Character:WaitForChild("Knife").Knife
local NewKnife = Knife:Clone()
Knife.Transparency = 1
NewKnife.Parent = workspace
local Magnitude = Knife.Position - Target
local TotalT = Magnitude / Velocity
local TotalDT = 0
local Origin = Knife.Position
NewKnife.CFrame = CFrame(NewKnife.Position, Target)
while TotalT > TotalDT do
local DT = RunService.RenderStepped:Wait()
TotalDT = TotalDT + DT
NewKnife.Position = Origin:Lerp(Target, TotalDT / TotalT)
end
end)