How do I make a part face in the direction of another?

Yes, I’m aware CFrame exists, and there’s many posts like this, but none of them use the same thing that I do and they don’t help me. I’m using TweenService to move the knife (which is the part).

local knife = script.Knife:Clone()
			local mouse = args[1]
			knife.Parent = game.Workspace
			knife.Position = player.Character.HumanoidRootPart.Position
			--knife.CFrame = CFrame.new(knife.Position, mouse.Position)
			--knife.CFrame = CFrame.lookAt(knife.Position, mouse.Position)
			
			local destroyed = false
			local movement = TS:Create(knife, TweenInfo.new((knife.Position - mouse.Position).Magnitude / 60), {Position = mouse.Position})
 			if game.Workspace:FindFirstChild("TSEffect") == nil then
				movement:Play()
				knife.CFrame = CFrame.new(knife.Position, mouse.Position)
				print((knife.Position - mouse.Position).Magnitude / 60)
				knife.Touched:Connect(function(hit)
					if hit.Parent.Name ~= player.Name then
						if hit.Parent:FindFirstChild("Humanoid") and destroyed == false then
							hit.Parent.Humanoid.Health -= 5
							knife.Sound:Play()
						end
						destroyed = true
						task.wait(0.2)
						knife:Destroy()
					end
				end)
			else
				movement:Pause()
			end
1 Like

I recommend using AssemblyLinearVelocity to move the knife since TweenService might change the knives’ pointing position I suppose.

Sorry if I’m wrong.

1 Like

How would I use AssemblyLinearVelocity?

1 Like

what do you mean by none of them use the same thing that you do?

You’re saying that this line does not work?

1 Like

They don’t use the same system.

It’s commented out?

1 Like

I dont understand. The fastest way to make a cframe face a vector3 is by using CFrame.lookAt. If the rotation is wrong then you can adjust using CFrame.Angles

I saw it was commented. But i was talking about when you used it. Did you even use it?

1 Like

Yes, I used it. How would I use CFrame.Angles?

1 Like

Multiply the Cframe.lookAt by CFrame.Angles.

Im not sure what it looks like when you do it. If possible, can I get a screenshot.

If not, you experiment with this.

CFrame.Angles(math.rad(90),0,0)

Move the math.rad in other axes, or probably change the value. Remember to multiply it to CFrame.lookat

2 Likes

for example:
Knife.AssemblyLinearVelocity = Knife.CFrame.LookVector * 100 (speed)

if you use this, you will need to make your knife unanchored and make it low or anti-gravity.

1 Like

He is using TweenService to move. His problem is the knife facing the direction its going.

1 Like

I can send a video tomorrow, but the knife faces down no matter what I do with the math.rad.

1 Like

Oh, ok. Send a screenshot or a video of the knife when you use lookat

1 Like

Ye I know but I’m recommending him to use Velocity because TweenService might result in unrealistic movement (the time going to the destination is always the same)

1 Like

Look at the code before assuming that they didnt do it or made an alternative.

they used the distance so its the same speed no matter how far.

1 Like

oh yeah my bad. Sorry for that xd.

1 Like

The knife faces down, no matter what I put.

I’m not sure what was different, but I basically used the same thing @Lielmaster said, and it worked. Here’s my code now.

local knife = script.Knife:Clone()
			local mouse = args[1]
			local target = args[2]
			knife.Parent = game.Workspace
			knife.Position = player.Character.HumanoidRootPart.Position
			
			local destroyed = false
			local movement = TS:Create(knife, TweenInfo.new((knife.Position - mouse.Position).Magnitude / 60), {Position = mouse.Position})
			if game.Workspace:FindFirstChild("TSEffect") == nil then
				knife.Anchored = false
				movement:Play()
				knife.CFrame = CFrame.lookAt(knife.Position, mouse.Position) * CFrame.Angles(math.rad(90), 0, 0)
				print((knife.Position - mouse.Position).Magnitude / 60)
				knife.Touched:Connect(function(hit)
					if hit.Parent.Name ~= player.Name then
						if hit.Parent:FindFirstChild("Humanoid") and destroyed == false then
							hit.Parent.Humanoid.Health -= 5
							print(hit.Parent.Name)
							knife.Sound:Play()
						end
						destroyed = true
						task.wait(0.2)
						knife:Destroy()
					end
				end)
			else
				movement:Pause()
				knife.Anchored = true
			end