Projectile faces the wrong way

I’m trying to make a knife throw script and it works fine, the trajectory of the projectile is completely straight anywhere you look at, but the problem is the projectile. It’s not facing the right way when it’s thrown, not the trajectory but the projectile itself. Images for context:

image

image

Script is down here:

local rp = game:GetService(“ReplicatedStorage”)
local KnifeThrow = rp:WaitForChild(“TheWorldRemotes”):WaitForChild(“KnifeThrow”)

local debris = game:GetService(“Debris”)

KnifeThrow.OnServerEvent:Connect(function(player)
local character = player.Character
local humanoid = character:WaitForChild(“Humanoid”)
local humanoidrp = character:WaitForChild(“HumanoidRootPart”)

local Stand = workspace:FindFirstChild(player.Name…" Stand"):FindFirstChild(“The World”)

local Folder = Instance.new(“Folder”, workspace)
Folder.Name = player.Name…" Knife Throw"
debris:AddItem(Folder,.5)

if Stand then
local prevWeld = Stand:WaitForChild(“HumanoidRootPart”):WaitForChild(“Stand Weld”)
prevWeld:Destroy()

  Stand:WaitForChild("HumanoidRootPart").CFrame = humanoidrp.CFrame * CFrame.new(0,0,-2.5)
  
  local weld = Instance.new("ManualWeld") --creates a new weld to move our stand forward
  weld.Name = "Stand Weld"
  weld.Part0 = Stand:WaitForChild("HumanoidRootPart")
  weld.Part1 = humanoidrp
  weld.C0 = Stand:WaitForChild("HumanoidRootPart").CFrame:inverse() * humanoidrp.CFrame
  weld.Parent = weld.Part0
  
  local AnimControl = Stand:WaitForChild("AnimControl")

for i, track in pairs(AnimControl:GetPlayingAnimationTracks()) do --stops previous animations
track:Stop()

  local Throw = AnimControl:LoadAnimation(script:WaitForChild("Throw"))
  Throw:Play()  --plays the animation
  
  local throwwhiff = Instance.new("Sound")
  throwwhiff.SoundId = "rbxassetid://536642316"
  throwwhiff.Volume = 1
  throwwhiff.Parent = Stand
  throwwhiff:Play()
  debris:AddItem(throwwhiff,2)

  
  local knifethrown = script.knifethrown:Clone()
  knifethrown.CFrame = Stand:WaitForChild("Right Arm").CFrame + Vector3.new(0,-1,0)
  knifethrown.Orientation = character:WaitForChild("Torso").CFrame.LookVector
  knifethrown.Parent = workspace
  debris:AddItem(knifethrown,15)
  
  local TimeStopped = player.Backpack:FindFirstChild("The World"):WaitForChild("TimeStopped")
  if TimeStopped.Value == true then
  	knifethrown.Anchored = true
  	end


  local vel = Instance.new("BodyVelocity",knifethrown)
  vel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
  vel.Velocity = character:WaitForChild("Torso").CFrame.LookVector * 65
  
  knifethrown.Touched:Connect(function(hit)
  		if hit:IsA("Part") or hit:IsA("MeshPart") then
  			local EHumanoid = hit.Parent:FindFirstChild("Humanoid")
  			
  			if EHumanoid then
  				knifethrown:Destroy()
  				
  				EHumanoid:TakeDamage(11)
  			    
  				local blood = Instance.new("ParticleEmitter")
  				blood.Parent = hit
  				blood.Texture = "rbxassetid://116830967"
  				blood.LightEmission = .125
  				blood.LightInfluence =  1
  				blood.Transparency = NumberSequence.new(.5,1)
  				blood.Lifetime = NumberRange.new(.3,.5)
  				blood.Rotation = NumberRange.new(45)
  				blood.RotSpeed = NumberRange.new(90)
  				blood.Speed = NumberRange.new(0)
  				blood.Size = NumberSequence.new(.95,1.25)
  				blood.Acceleration = Vector3.new(0,-5,0)
  				debris:AddItem(blood,10)
  				
  				local throwhitting = Instance.new("Sound")
  				throwhitting.Volume = 1
  				throwhitting.SoundId = "rbxassetid://186311262"
  				throwhitting.Parent = workspace
  				throwhitting:Play()
  				debris:AddItem(throwhitting,16)
  				

  				
  				
  			end
  		end
  end)
  
  wait(1)
  local prevWeld = Stand:WaitForChild("HumanoidRootPart"):WaitForChild("Stand Weld")
  	prevWeld:Destroy()
  	
  	Stand:WaitForChild("HumanoidRootPart").CFrame = humanoidrp.CFrame * CFrame.new(2,0,2)
  	
  	local weld = Instance.new("ManualWeld")
  	weld.Name = "Stand Weld"
  	weld.Part0 = Stand:WaitForChild("HumanoidRootPart")
  	weld.Part1 = humanoidrp
  	weld.C0 = Stand:WaitForChild("HumanoidRootPart").CFrame:inverse() * humanoidrp.CFrame
  	weld.Parent = weld.Part0
  	
  	local idle = AnimControl:LoadAnimation(script:WaitForChild("Idle"))
  	idle:Play()

wait(7)
knifethrown.Anchored = false

end

KnifeThrow:FireClient(player)

end
end)

if you know what’s causing this issue, please help.

Can you explain what you’ve tried to do to fix the problem?

I’ve tried to use the latest response’s suggestion but to no avail, since the projectile isn’t launched from a tool/isn’t in your hand instead it copies it from replicated storage i can’t use the current position value cause it throws from where it is on the baseplate.

what i mean for latest responses suggestion is in my other post in which the person suggested this:

Cframe.new(projectile.Position,whatEverNeedsToBeFaced.Position)

That looks like the correct approach, though that function is deprecated.

What variable did you set that CFrame to? What change did you see after you made the change?

The knife has a set orientation that you may have to correct. You could have a row of different knives that all look to be facing the exact way, but the engine could see them as facing completely different ways. Try tossing in a *CFrame.Angles(math.rad(0), math.rad(180), math.rad(0))
You’ll have to guess what the x,y,z numbers will be, but they should be multiples of 90.

tried

knifethrown.CFrame = CFrame.new(Stand.Torso.Position, knifethrown.Position)

result: the same thing

i think the problem here is the velocity value that the projectile uses to be launched it’s set to

local vel = Instance.new("BodyVelocity",knifethrown)
		vel.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
		vel.Velocity = character.Torso.CFrame.lookVector * 65

do you think this could be the issue?

You said the trajectory is fine but not the projectile.

The BodyVelocity should be fine, it doesn’t try to rotate the projectile.

I don’t know exactly what you’re doing in your code, but try this

local knifethrown = script.knifethrown:Clone()
knifethrown.CFrame = CFrame.new(WhereTheKnifeSpawns.Position, WhereTheKnifeIsAimingTowards.Position)
knifethrown.CFrame = knifethrown.CFrame* CFrame.Angles(math.rad(0), math.rad(180), math.rad(0))
 --change the x,y,z values of the CFrame.Angles until you get the right rotation

the solution is fine but then when i try it with the values on (math.rad(0), math.rad(180), math.rad(0))
it works just for when the character is facing north, but when he faces south it does the same thing, i’ll keep trying to change the values

Did you run my recent code. That was a problem of your original code, it would only work for one specific orientation, my code should work at any orientation as long as you feed it the right variables when you start.

I’m running your code with my values but i don’t have the “WhereTheKnifeIsAimingTowards” position and i tried to set it to the character’s torso and it just won’t show up

local knifethrown = script.knifethrown:Clone()
		knifethrown.CFrame = CFrame.new(knifethrown.Position,character.Torso.Position)
		knifethrown.CFrame = knifethrown.CFrame* CFrame.Angles(math.rad(0), math.rad(180), math.rad(0))
		debris:AddItem(knifethrown,15)

You said knifethrown.Position. What is that?

When I run into problems like this where its a small section of code that is wrong, I break it down to just that section.

Open a new studio file and put down two bricks; KnifeStart and KnifeDestination.
Then put your knife object in the workspace

Run this code

while true do
wait()
workspace.Knife.CFrame = CFrame.new(workspace.KnifeStart.Position, workspace.KnifeDestination.Position)*CFrame.Angles(math.rad(0), math.rad(180), math.rad(0))
end

Adjust the values until this works, then reincorporate it into your original code once you understand the solution and understand what the problem was before.

I tried it myself. The knife being the thin part attached to a thicker one:

1 Like

knifethrown.Position is the position of the knife in the workspace, the origin point of where it is. as to the code that you suggested it works fine but how am i supossed to make a knife destination part on a person when the knife is thrown?

The knife destination position can be a certain distance ahead of the player, the bodyvelocity will take care of where the knife will actually land.

workspace.Part.CFrame = workspace.BrokenBone.Head.CFrame + workspace.BrokenBone.Head.CFrame.lookVector*2

This, for example, places the part 2 studs ahead of the character’s head.

With this and my other code, you have the knife starting position and the position where the knife is destined to go. The orientation is figured out with both of these vectors, and then the bodyvelocity makes it fly in that direction and physics handles where the knife will actually go

edit: BodyVelocity will require some coding of its own to work, but my code will get you the right knife position and orientation

while true do
wait(.4)
local Head = workspace.BrokenBone.Head
local knifeEndCFrame = Head.CFrame + Head.CFrame.lookVector*8
local knifeStartCFrame = Head.CFrame + Head.CFrame.lookVector*4
workspace.Union.CFrame = CFrame.new(knifeStartCFrame.p, knifeEndCFrame.p)*CFrame.Angles(0, math.rad(90), 0)
end

There’s certainly better ways of doing this, but this is a basic way of understanding how the knife should be placed

local KnifeStart = Instance.new("Part",character)
			KnifeStart.Name = "KnifeStart"
			KnifeStart.Transparency = 1
			KnifeStart.CanCollide = false
	        KnifeStart.Massless = true
			KnifeStart.Anchored = true
			KnifeStart.CFrame = character.Head.CFrame + character.Head.CFrame.lookVector*4
			
			local KnifeDestination = Instance.new("Part",character)
			KnifeDestination.Name = "KnifeDestination"
			KnifeDestination.Transparency = 1
			KnifeDestination.CanCollide = false
	        KnifeDestination.Massless = true
			KnifeDestination.Anchored = true
			KnifeDestination.CFrame = character.Head.CFrame + character.Head.CFrame.lookVector*100

			while knifeisthrown.Value == false do
			wait()
			workspace.knifethrown.CFrame = CFrame.new(KnifeStart.Position, KnifeDestination.Position)*CFrame.Angles(math.rad(0), math.rad(180), math.rad(0))

i did this but the knife wont show up, this is very frustrating

knifeisthrown value is just a way to make it not overlap forever so while the knife hasn’t been thrown yet you can throw it

you can change orientation of the knife with CFrame.Angles(math.rad(),0,0) with values, or use knife.Orientation = Vector3.new()–x,y,z values here