AI repeatedly backs up and goes towards npc

AI keeps backing up and going towards the NPC with nothing changing at all. (red part is damage brick) What’s wrong? xqiWj8loek

-- i think the issue might be here 
function backUp(target)
	hum:Move(-(target.Position - head.Position).Unit)
end

function main()
	local target = findTarget()
	if target then
		if getDistance(target) > backUpDistance then -- yet another check to see if we're too close
			pathToTarget(target)
			elseif getDistance(target) < 5.1 then
				backUp(target)
			elseif getDistance(target) > backUpDistance and not canSee(target) then
				pathToTarget(target)
			elseif getDistance(target) > 6 and getDistance(target) < 8 then
				attack(target)
		end
	else
		explore()
	end
end

while wait() do
	if hum.Health > 0 then
		main()
	else
	break
	end
end

I think the problem is that as soon the bot gets too far, it starts walking back. And when it gets too close, it starts walking away.

You could make it so that the bot only walks up to targetPos + ((botPos - targetPos).Unit * 5)

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