When my npc reaches its designated position, the player is able to walk behind it and avoid its attacks since its orientation doesnt automatically track the player. Using CFrames causes stuttering, so I was wondering if there is a way I can match npc orientation to the player orientation while avoiding the stuttering? Script:
while npctable.MachineState.Value == "chase" do
if not npctable.Target then return "FAIL" end
if not npctable.Path then break end
local TargetPos = TargetMidPoint.Position
local MidPos = MidPoint.Position
local direction = (TargetPos - MidPos).Unit
local movetoPos = TargetPos - direction * StopDistance
-- doing this instead of targetpos has led to some choppiness
-- print(Humanoid.WalkSpeed)
if not npctable.Target then return "FAIL" end
local distance = (MidPos - TargetPos).Magnitude
if distance < (attackrange - 3) and npctable.CanAttack then
local Inversed = npctable.MidPoint.CFrame:Inverse() * TargetMidPoint.CFrame
if Inversed.Z < 0.5 then
return "SUCCESS"
end
elseif distance > npctable.Range then
return "FAIL"
end
if distance <= 8 then
updatetime = 0.1
elseif distance >= 15 then
updatetime = 0.35
end
if distance > 16 then
if not TrackRun or time() - TrackRun > 3 then
Replicator:CreateEffect("Speed", {Value = 6}):Debris(2)
TrackRun = time()
end
end
-- if Path.Status == Path.StatusType.Active then
-- Path:Stop()
-- end
if distance < attackrange then
Humanoid:MoveTo(movetoPos)
else
npctable.Path:Run(movetoPos)
end
local StartTick = tick()
repeat
task.wait()
until ((tick() - StartTick) > updatetime)
end