I’m trying to make it so that the player character turns towards the NPC when it approaches. Currently the NPC hits the distance limit and the player character starts going crazy. Any help would be appreciated.
-
The plrbody variable is the HumanoidRootPart.
-
The prints show that it should be doing what I want it to do.
local Duration = 3
local TurnFunc
for _, waypoint in pairs(waypoints) do
if (NFJbody.Position - plrbody.Position).magnitude >= 10 then
hum:MoveTo(waypoint.Position)
hum.MoveToFinished:Wait()
else
local CurrentAngle = plrbody.Orientation.y
local ANGLE = NFJbody.Orientation.y + 180
TurnFunc = game:GetService("RunService").Heartbeat:Connect(function(delta)
print(CurrentAngle)
print(ANGLE)
print(NFJbody.Orientation.y)
print(plrbody.CFrame)
local adjustment = ANGLE*(delta/Duration)
if CurrentAngle + adjustment < ANGLE then
CurrentAngle += adjustment
else
CurrentAngle = ANGLE
plrbody.Orientation = Vector3.new(0,math.rad(CurrentAngle),0)
TurnFunc:Disconnect()
end
plrbody.Orientation = Vector3.new(0,math.rad(CurrentAngle),0)
end)
end
end