Manually rotating the humanoid whilst it is moving (using :MoveTo())

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to gradually rotate the humanoid towards the player while the humanoid is moving without using AutoRotate.

  2. What is the issue? Include screenshots / videos if possible!
    Whenever I rotate the humanoid, it does not move anymore.

In the first video, the NPC I am creating, Knightmage, is moving towards the player in straight lines, updating every second. In the second video, Knightmage I have un-commented out the turning section of the script and now that it is turning, it does not move anymore.

Knightmage walking in straight lines towards the player, updating every second

Knightmage turning towards the player, but not allowing him to move

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I have attempted to look for solutions on the Developer Hub.

I have attempted to use CFrame.Rotation and .Rotation instead of just .CFrame but those ran into the same issue, aswell as .Rotation reaching a dead-end of rotation and not rotating any further.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

My best guess as to why it is doing this is that it is constantly setting the CFrame of Knightmage to the same position, except rotated. I however am unable to figure out how to rotate him whilst he is moving. He is using the :MoveTo() function in order to move.

Here is the rotating script

-- rotates Knightmage

RunService.Heartbeat:Connect(function(DeltaTime)
	local player,distance = getClosestPlayer(script.Parent.HumanoidRootPart.Position)
	
	local cframe = NPC.HumanoidRootPart.CFrame --the CFrame of the object
	local position = player.HumanoidRootPart.Position --the position we want to check

	local rightVector = cframe.RightVector

	local directionToPosition = position - cframe.Position

	if rightVector:Dot(directionToPosition) > 0 then
		
		-- rotates Knightmage right
		
		NPC.HumanoidRootPart.CFrame *= CFrame.fromEulerAnglesXYZ(0,math.rad(-1),0)
	else --If the dot product is 0 the position is directly in front
		
		-- rotates Knightmage left
		
		NPC.HumanoidRootPart.CFrame *= CFrame.fromEulerAnglesXYZ(0,math.rad(1),0)
	end
	
end)

Here is the movement script

-- moves knightmage

while true do
	local player, distance = getClosestPlayer(script.Parent.HumanoidRootPart.Position)
	
	-- checks if the player exists and is above 0 health
	
	if player and distance < 5000000 and player.Humanoid.Health ~= 0 then
		
		-- creates a new part for knightmage to walk to
		
		local PositionPart = Instance.new("Part")
		PositionPart.Name = "KnightmagePostion"
		PositionPart.Size = Vector3.new(0.1,0.1,0.1)
		PositionPart.Transparency = 1
		PositionPart.CanCollide = false
		PositionPart.Anchored = true
		PositionPart:PivotTo(CFrame.new((player.HumanoidRootPart.Position - NPC.HumanoidRootPart.Position) * 5))
		PositionPart.Parent = workspace
		
		-- makes knightmage move to the part's position while also setting the network owner
		
		local Position = PositionPart.Position
		NPC.HumanoidRootPart:SetNetworkOwner(Players:GetPlayerFromCharacter(player))
		NPC.Humanoid:MoveTo(Position, PositionPart)
		
		-- removes the part that knightmage moves to
		
		game:GetService("Debris"):AddItem(PositionPart,1)
	end
	wait(1)
end

I am essentially attempting to copy this character.