(one time hire)

I’m willing to pay someone over 25 dollars if you can help me with this scripting stuff, I have a pathfinding ai and it works pretty fine but i would like someone to make it better what I mean by better is like the ai can only see you once it’s facing ur direction but the ai rn I use it can spot you when it’s not looking at you which is unrealistic another thing is when you turn a corner the ai instantly looses you and that’s unrealistic so could you make it where once you turn a corner the ai still targets you until 4 seconds later of loosing you, if the ai spots you after you turn the corner the timer resets and last thing is where once you get close to the monster your screen starts to shake with sound the closer the monster gets to you the louder the sound gets and the more shakey your screen gets here’s a sum up of what I want

-Ai footsteps shaking your screen when it gets close
-Ai still targeting you after you turn a corner
-Ai targeting you only ifs it’s looking your direction

If you don’t know how to do all you can do atleast 1 of them and we can work on a money arrangement if I explained bad please tell me what you don’t understand

script is

local humanoid = teddy.Humanoid
teddy.PrimaryPart:SetNetworkOwner(nil)

local function canSeeTarget(target)
	local origin = teddy.HumanoidRootPart.Position
	local direction = (target.HumanoidRootPart.Position - teddy.HumanoidRootPart.Position).unit * 230
	local ray = Ray.new(origin, direction)
	
	local hit, pos = workspace:FindPartOnRay(ray, teddy)
	
	
	if hit then
		if hit:IsDescendantOf(target) then
			return true
		end
	else
		return false
	end
end

local function findTarget()
	local players = game.Players:GetPlayers()
	local maxDistance = 50
	local nearestTarget
	
	for index, player in pairs(players) do
		if player.Character then
			local target = player.Character
			local distance = (teddy.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude
			
			if distance < maxDistance and canSeeTarget(target) then
				nearestTarget = target
				maxDistance = distance
			end
		end
	end
	
	return nearestTarget
end

local function getPath(destination)
	local PathfindingService = game:GetService("PathfindingService")
	
	local pathParams = {
		["AgentHeight"] = 9,
		["AgentRadius"] = 6,
		["AgentCanJump"] = false
	}
	
	local path = PathfindingService:CreatePath(pathParams)
	
	path:ComputeAsync(teddy.HumanoidRootPart.Position, destination.Position)
	
	return path
end

local function attack(target)
	local distance = (teddy.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude

	if distance > 0.1 then
		humanoid:MoveTo(target.HumanoidRootPart.Position)
	else
		local attackAnim = humanoid:LoadAnimation(script.Attack)
		attackAnim:Play()
		target.Humanoid.Health = 0
	end
end

local function walkTo(destination)
	
	local path = getPath(destination)
	
	if path.Status == Enum.PathStatus.Success then
		for index, waypoint in pairs(path:GetWaypoints()) do
			local target = findTarget()
			if target and target.Humanoid.Health > 0 then
				attack(target)
				break
			else
				humanoid:MoveTo(waypoint.Position)
				humanoid.MoveToFinished:Wait()
			end
		end
	else
		humanoid:MoveTo(destination.Position - (teddy.HumanoidRootPart.CFrame.LookVector * 10))
	end
end

function patrol()
	local waypoints = workspace.waypoints3:GetChildren()
	local randomNum = math.random(1, #waypoints)
	walkTo(waypoints[randomNum])
end

while wait(0.1) do
	patrol()
end

This topic was automatically closed after 0 minutes. New replies are no longer allowed.