Hello Developers!
The title addresses my issue, the issue that I have with my ranged boss NPC is that whenever it backs up when the player moves close to it, it causes it to twitch.
I know why it’s twitching, just I don’t know how to fix it.
local function EvadeNearbyPlayer()
for _, Players in pairs(Players:GetChildren()) do
local Character = Players.Character or Players.CharacterAdded:Wait()
if Character == nil then
return
end
local distanceBetweenNPCandPLayer = (Character.PrimaryPart.Position - TemplateR6.PrimaryPart.Position)
if distanceBetweenNPCandPLayer.Magnitude <= ConfroZone then
local RunAwayDistance = (Character.PrimaryPart.Position - TemplateR6.PrimaryPart.Position) * -1
Humanoid:Move(RunAwayDistance,false)
elseif distanceBetweenNPCandPLayer.Magnitude >= ConfroZone then
Humanoid:Move(Vector3.new(0,0,0),false)
end
end
end
local function PointAtPlayer()
for _, Players in pairs(Players:GetChildren()) do
local Character = Players.Character or Players.CharacterAdded:Wait()
if Character == nil then
return
end
TemplateR6:PivotTo(CFrame.lookAt(TemplateR6.PrimaryPart.Position, Character.PrimaryPart.Position * Vector3.new(1, 0, 1) + TemplateR6.PrimaryPart.Position * Vector3.new(0, 1, 0)))
task.wait()
end
end