How can I make my npc rotate slowly to the player?

Is there anyway I can make the npc turn slowly towards the player? Currently the npc just suddenly turns towards the player (if you really need a video ill try to provide you with one)

Code I use to turn the Npc:

		local NPCroot = npc.HumanoidRootPart
		local Character = player.Character
		local CharRoot = Character.HumanoidRootPart

		Npc:SetPrimaryPartCFrame(CFrame.lookAt(
			NPCroot.Position,
			CharRoot.Position * Vector3.new(1, 0, 1)
				+ NPCroot.Position * Vector3.new(0, 1, 0)
			))

Any solutions or ideas?
Thanks

You can use bodygyros which help you control the speed of how fast the turning takes place

Using the maxtorque/P property, you can determine it. Play around with the properties.

Try using TweenService, I think that can work

Do you know how I can get the Vector I need to make it face the player?

I think this should work

local Vector = CharRoot.Position * Vector3.new(1, 0, 1)+ NPCroot.Position * Vector3.new(0, 1, 0)

I thought they were deprecated and illegal to use?

Nah you can still use it, I needed it for my flying script. It’s realy easy to use and sometimes its better to use bodygyro/bodyposition

For example, you can’t use alignorientation to align something like the character’s head to the camera because you can’t add an attachment to the camera. The only possible way to do that would be to constantly set a part’s CFrame to the camera’s CFrame with a while loop.

Same for bodygyros but atleast you don’t need to do that, plus much simpler to use.

Although the best solution in this case would be to use tweenservice.

TweenService

-- code not complete, i just provided a placeholder

local goal = {}
goal.CFrame = CFrame.lookAt(NPCroot.Position, CharRoot.Position * Vector3.new(1, 0, 1) + NPCroot.Position * Vector3.new(0, 1, 0))

-- your tween info

local tween = TweenService:Create(NPCroot, tweenInfo, goal)
tween:Play()

I made a script and it works fine for me

2 Likes

You can run a Heartbeat loop where the NPC’s rotation is Lerped to the final target based on an Alpha. [linear interpolation]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.