function movement.strafe()local i=(status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")).Position local F,r=myRoot.Position,nil local G=math.random(2)if G==1 then r=myRoot.CFrame.RightVector elseif G==2 then r=-myRoot.CFrame.RightVector end for i=1,10,1 do if not core.raycast(F,r*2)and core.raycast(F,Vector3.new(0,-7,0))then F+=r*2 else F+=r*-2 break end end local h,A=core.raycast(F,((status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")).Position-F).Unit*30)if A then if A.Instance:IsDescendantOf((status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")).Parent)then else F=myRoot.Position end F=myRoot.Position end return F end function checkDirection(i)local F=(status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")).Position local r=myRoot.Position local G=false for F=1,5,1 do if not core.raycast(r,i*1)and core.raycast(r,Vector3.new(0,-7,0))then r=r+i*1 else r=r+i*-1 break end if F==5 then G=true end end return G,r end function movement.retreat()local i,F=checkDirection(-((status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")).Position-myRoot.Position).Unit)if i then return F end i,F=checkDirection(myRoot.CFrame.RightVector)if i then return F end i,F=checkDirection(-myRoot.CFrame.RightVector)if i then return F end return myRoot.Position end function movement.slowAdvance()local i=(status:get("\099\117\114\114\101\110\116\084\097\114\103\101\116")).Position local F=myRoot.Position local r=30 repeat r-=1 if not core.raycast(F,(i-F).Unit*1)and core.raycast(F,Vector3.new(0,-7,0))then F=F+(i-F).Unit*1 else F=F+(i-F).Unit*-1 break end if r<=0 then break end until false return F end
--When strafing make sure you can see target from end pos
function movement.strafe()
	local goalPos = status:get("currentTarget").Position
	local origin, dir = myRoot.Position, nil

	local action = math.random(2)
	if action == 1 then
		dir = myRoot.CFrame.RightVector
	elseif action == 2 then
		dir = -myRoot.CFrame.RightVector
	end

	for _ = 1, 10 do
		if not core.raycast(origin, dir * 2) and core.raycast(origin, Vector3.new(0, -7, 0)) then
			origin += dir * 2
		else
			origin += dir * -2
			break
		end
	end

	local _, result = core.raycast(origin, (status:get("currentTarget").Position - origin).Unit * 30)
	if result then
		if result.Instance:IsDescendantOf(status:get("currentTarget").Parent) then
		else
			origin = myRoot.Position
		end
		origin = myRoot.Position
	end

	return origin
end

function checkDirection(dir)
	local goalPos = status:get("currentTarget").Position
	local origin = myRoot.Position

	local success = false
	for i = 1, 5 do
		if not core.raycast(origin, dir * 1) and core.raycast(origin, Vector3.new(0, -7, 0)) then
			origin = origin + dir * 1
		else
			origin = origin + dir * -1
			break
		end

		if i == 5 then
			success = true
		end
	end

	return success, origin
end

function movement.retreat()
	--Check if we can retreat directly from the enemy.
	local result, pos = checkDirection(-(status:get("currentTarget").Position - myRoot.Position).Unit)
	if result then
		return pos
	end

	--Check if we can move away to the right.
	result, pos = checkDirection(myRoot.CFrame.RightVector)
	if result then
		return pos
	end

	--Check if can move away to the left.
	result, pos = checkDirection(-myRoot.CFrame.RightVector)
	if result then
		return pos
	end

	return myRoot.Position
end

function movement.slowAdvance()
	local goalPos = status:get("currentTarget").Position
	local origin = myRoot.Position

	local maxIterations = 30
	repeat
		maxIterations -= 1
		if not core.raycast(origin, (goalPos - origin).Unit * 1) and core.raycast(origin, Vector3.new(0, -7, 0)) then
			origin = origin + (goalPos - origin).Unit * 1
		else
			origin = origin + (goalPos - origin).Unit * -1
			break
		end
		if maxIterations <= 0 then
			break
		end
	until false

	return origin
end
