NPC Twitches while backing up away from the player

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

I am not able to test this on my end, but perhaps make a Boolean if the player is moving, and disable the PivotTo statement if the player is trying to move, the CFrame being changed is possibly preventing the movement.

You want me to disable the PivotTo()? No, I don’t wanna do that since I want the NPC to still point at me, even if it’s moving back.

Try it and see if that helps. The thing is, Pivot To also overwrites the positional CFrame, and constant calling of the Method could interfere with the movement potentially

You have to work with me to find a solution, so try it.

Alright then.
{Filler Filler Filler}

Instead of :PivotTo() use AlignOrientation and set its CFrame property to what you’re setting now in the PivotTo.

AlignOrientation.CFrame = CFrame.lookAt(TemplateR6.PrimaryPart.Position, Character.PrimaryPart.Position * Vector3.new(1, 0, 1) + TemplateR6.PrimaryPart.Position * Vector3.new(0, 1, 0))

It I guess it does work, but it only aims at me when I turn back, which is something I don’t want.

So, apparently turning off AutoTurn fixed the issue, sorry.

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