How do I rotate the character smoothly to the cursor position?

I’m trying to make a melee weapon similar to those in Combat Initiation, but I dont really know how to make it smoothly rotate the character to the orientation.
This is how it currently works

How i intended it to work

So as an alternative, currently it snaps the character to where the cursor is facing. Any suggestions on how? Here’s the snippet of code.

	equipped = true
	if player.Character and UserInputService.MouseBehavior ~= Enum.MouseBehavior.LockCenter and equipped then
		local rootPart = player.Character:FindFirstChild("HumanoidRootPart")
		local mouseLocation = Vector3.new(mouse.Hit.X, rootPart.Position.Y, mouse.Hit.Z)
		rootPart.CFrame = CFrame.new(rootPart.Position, mouseLocation)
		hum.AutoRotate = false
	end
end)

tool.Unequipped:Connect(function()
	equipped = false
	hum.AutoRotate = true
end)

local function onAim()
	if player.Character and UserInputService.MouseBehavior ~= Enum.MouseBehavior.LockCenter and equipped then
		local rootPart = player.Character:FindFirstChild("HumanoidRootPart")
		local mouseLocation = Vector3.new(mouse.Hit.X, rootPart.Position.Y, mouse.Hit.Z)
		rootPart.CFrame = CFrame.new(rootPart.Position, mouseLocation)
		hum.AutoRotate = false
	else
		hum.AutoRotate = true
	end
end

ContextActionService:BindAction("Aim", onAim, false, Enum.UserInputType.MouseMovement)```
1 Like

I’ve seen other posts about this same topic. Try searching the forums with different terminology than you’d expect to find (rotate npc smoothly, move player smoothly with mouse, aim player at mouse, etc.).
From what I remember they use Lerping or Tweening to accomplish the smooth effect.

1 Like

I’ve found this forum that solved most of my issues. Thanks!

1 Like