Can't figure out how agent parameters work

Helloo my monster keeps running into walls. im aware that youre supposed to set agent parameters to the path, but whenever i do, the character becomes stuck. How does it even work???



i set the params to the one in the documentation, and tried to change it around a bit, but nope still stuck in place

1 Like

You got the code for me to look at?




local char = script.Parent
local humanoid = char.Humanoid
local model = char.Model
char.PrimaryPart:SetNetworkOwner(nil)
local pathFinder = game:GetService("PathfindingService")

local destinations = game.Workspace.Destinations:GetChildren()

local always = true

local assets = char.Assets
local anims = assets.Anims
local values = assets.Values
local sfx = assets.Sfx

local Idle = humanoid.Animator:LoadAnimation(anims.Idle)
local Walk = humanoid.Animator:LoadAnimation(anims.Walk)
local Attack = humanoid.Animator:LoadAnimation(anims.Attack)
local Found = humanoid.Animator:LoadAnimation(anims.Found)
local Run = humanoid.Animator:LoadAnimation(anims.Run)


local chasingplayer = false
local RS = game:GetService("ReplicatedStorage")
local currenttarget = nil

local chasedplayervalue


local cries = {
	model.Cry1,
	model.Cry2,
	model.Cry3,
}

Idle:Play()


local walkingthingy = 1
Walk:GetMarkerReachedSignal("StepSfx"):Connect(function()
	if Walk.IsPlaying then

		
		if walkingthingy == 1 then
			walkingthingy += 1
			model.Step1:Play()
		else
			walkingthingy = 1
			model.Step2:Play()
		end
	end
end)

local runningthingy = 1
Run:GetMarkerReachedSignal("StepSfx"):Connect(function()
	if Run.IsPlaying then


		if runningthingy == 1 then
			runningthingy += 1
			model.Stomp1:Play()
			model.Step1:Play()
		else
			runningthingy = 1
			model.Stomp2:Play()
			model.Step2:Play()
		end
	end
end)


Idle:GetMarkerReachedSignal("CrySfx"):Connect(function()
	if Idle.IsPlaying then
		cries[math.random(1, #cries)]:Play()
	end
end)

Attack:GetMarkerReachedSignal("AttackSfx"):Connect(function()
	if Attack.IsPlaying then
		RS.ReplicatedEvents.AttackPlayer:FireClient(game.Players:GetPlayerFromCharacter(currenttarget))
		currenttarget.Model.TextureID = currenttarget.Assets.Emotes.Hurt.Texture
		model.Attack:Play()
		task.wait(2)
		currenttarget.Model.TextureID = currenttarget.Assets.Emotes.Normal.Texture
	end
end)

Found:GetMarkerReachedSignal("CaughtSfx"):Connect(function()
	if Found.IsPlaying then
		RS.ReplicatedEvents.SeePlayer:FireClient(game.Players:GetPlayerFromCharacter(currenttarget))
		model.Wail:Play()
	end
end)


local PAUSEWALKING = false

local touching = false
local interestTime = 1
local interestTimer = 0

local walking = false
local running = false

local target = nil

local PlayerTargets = {
	
}

local function findNearestPlayer(settingtarget)
	local nearestPlayer = nil
	local shortestDistance = 80
	for _, player in pairs(game.Players:GetChildren()) do
		
		local thing = player.Character
		if thing and thing:FindFirstChild("IsAMonster") == nil then
			local hrp = thing:FindFirstChild("HumanoidRootPart")
			if hrp then
				currenttarget = thing
				local distance = (char.HumanoidRootPart.Position - hrp.Position).Magnitude
				if distance <= shortestDistance then
					table.insert(PlayerTargets, {Character = thing, Distance = distance, Hrp = hrp})
				end
			end
		end
	end
	
	local LeastStealth = 6
	local MyTarget = nil
	for i, entry in pairs(PlayerTargets) do
		if entry.Character.Stealth.Value < LeastStealth then
			MyTarget = entry
			LeastStealth = entry.Character.Stealth.Value
		elseif entry.Character.Stealth.Value  == LeastStealth then
			if entry.Distance < MyTarget.Distance then
				MyTarget = entry
			end
		end
	end
	
	if MyTarget then
		if MyTarget.Distance < 8 then
			if touching == false then
				interestTimer = 0 
				Run:Stop()
				Walk:Stop()
				Attack:Play()
				touching = true

				target = nil
				PAUSEWALKING = true
				humanoid.WalkSpeed = 0
				Attack.Ended:Wait()

				Idle:Play()
				walking = false
				wait(3)
				PAUSEWALKING = false
				touching = false
			end

		else
			local rayOrigin = char.HumanoidRootPart.Position
			local rayDirection = (MyTarget.Hrp.Position - rayOrigin).Unit * MyTarget.Distance

			local raycastResult = game.Workspace:Raycast(rayOrigin, rayDirection)

			if raycastResult and raycastResult.Instance:IsDescendantOf(MyTarget.Character) then
				interestTimer = interestTime
				nearestPlayer = MyTarget.Character
				shortestDistance = MyTarget.Distance
			end
		end
	end
	
	
	table.clear(PlayerTargets)
	if settingtarget == true then
		if not nearestPlayer and interestTimer > 0 then
			nearestPlayer = currenttarget 
			interestTimer = interestTimer - task.wait(0.1) 
			if interestTimer == 0 then
				currenttarget = nil
			end
		end
	end

	return nearestPlayer
end

local possibledestinations = {}
local currentobjecttarget = nil
local blacklist = destinations
table.insert(blacklist, model)
local function DecideWaypoint()
	local leastdistance = 150
	local GoHere
	--print(destinations)
	for i, waypoint in ipairs(destinations) do
		local distance = (char.HumanoidRootPart.Position - waypoint.Position).Magnitude
		if distance <= leastdistance and waypoint ~= currentobjecttarget then
			local rayOrigin = char.HumanoidRootPart.Position
			local rayDirection = (waypoint.Position - rayOrigin).Unit * distance
			local raycastParams = RaycastParams.new()

			raycastParams.FilterDescendantsInstances = blacklist
			raycastParams.FilterType = Enum.RaycastFilterType.Exclude
			local raycastResult = game.Workspace:Raycast(rayOrigin, rayDirection)

			if raycastResult and raycastResult.Instance:IsDescendantOf(game.Workspace.Destinations) then
				table.insert(possibledestinations, waypoint)
			end
		end
	end

	if #possibledestinations > 1 then
		GoHere = possibledestinations[math.random(1, #possibledestinations)]
	else
		GoHere = possibledestinations[1]
	end
	currentobjecttarget = GoHere
	
	table.clear(possibledestinations)
	return GoHere

end


--char.HitRadius.Touched:Connect(function(part)
--	if part.Parent:FindFirstChild("Humanoid") and part.Parent:FindFirstChild("IsAMonster") == nil and part.Parent == target then
--		if touching == false then
--			Run:Stop()
--			Walk:Stop()
--			Attack:Play()
--			touching = true

--			target = nil
--			PAUSEWALKING = true
--			humanoid.WalkSpeed = 0
--			Attack.Ended:Wait()

--			Idle:Play()
--			walking = false
--			wait(5)
--			PAUSEWALKING = false
--			touching = false
--		end
--	end
--end)

local path = nil
local idling = false


Walk:Play()


local timerCoroutine = nil

local curdesk

local function StartIdling()
	if timerCoroutine then
		coroutine.close(timerCoroutine)
	end

	timerCoroutine = coroutine.create(function()
		PAUSEWALKING =true
		task.wait(math.random(2, 5))
		if chasingplayer == false then
			PAUSEWALKING = false
		end
	end)

	coroutine.resume(timerCoroutine)
end
local function WalkingThingIdk()
	if timerCoroutine then
		coroutine.close(timerCoroutine)
	end

	timerCoroutine = coroutine.create(function()
		humanoid.MoveToFinished:Wait()
		walking = false
	end)

	coroutine.resume(timerCoroutine)
end



task.spawn(function()
	while always do

		target = findNearestPlayer(true)
		
		if target and target:IsA("Model") and touching == false then
			humanoid.WalkSpeed = values.MaxWalk.Value
			PAUSEWALKING = false
		end
		
		if PAUSEWALKING == false then
			--if chasingplayer == false then
			--	WalkAnim:Stop()
			--end


			if not target then
				target = DecideWaypoint()
			end

			if chasingplayer == true and not walking then
				Idle:Stop()	
				Run:Play()
				walking = true
			end
			
			path = pathFinder:CreatePath()


			if target:FindFirstChild("Humanoid") and target:IsA("Model") and target.Humanoid.Health ~= 0 then

				if chasingplayer == false then
					char.HumanoidRootPart.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
					Found:Play()
					Found.Ended:Wait()
					if not walking then
						humanoid.WalkSpeed = values.MaxWalk.Value
						Idle:Stop()	
						Run:Play()
						walking = true
					end
				end
				
				if char:FindFirstChild("HumanoidRootPart") then
					path:ComputeAsync(char.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
					chasingplayer = true
				else
					humanoid.WalkSpeed = values.MinWalkWalk.Value
					chasingplayer = false
					target = nil
					Run:Stop()	
					Walk:Play()
					walking = true
				end

			else
				humanoid.WalkSpeed = values.MinWalk.Value
				Idle:Stop()	
				Run:Stop()
				Walk:Play()
				walking = true
				path:ComputeAsync(char.HumanoidRootPart.Position, target.Position)
				if chasingplayer == true then
					chasingplayer = false
					if currenttarget ~= nil then
						currenttarget = nil
					end
				end
				
				
				local interrupt = false
				WalkingThingIdk()
				repeat
					task.wait()
					if findNearestPlayer(false) then
						interrupt = true
						break
					end
				until walking == false
				
				
				if not interrupt then
					walking = false
					Walk:Stop()
					Idle:Play()
					StartIdling()
				else
					
					target = findNearestPlayer(true)
					
					humanoid.WalkSpeed = 0
					if chasingplayer == false then
						char.HumanoidRootPart.CFrame = CFrame.lookAt(char.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
						Found:Play()
						walking = false
						Found.Ended:Wait()
						if not walking then
							humanoid.WalkSpeed = values.MaxWalk.Value
							Idle:Stop()	
							Run:Play()
							walking = true
						end
					end

					if char:FindFirstChild("HumanoidRootPart") then
						path:ComputeAsync(char.HumanoidRootPart.Position, target.HumanoidRootPart.Position)
						chasingplayer = true
					end
				end

			end

		end
		task.wait()
	end
end)

game:GetService("RunService").Heartbeat:Connect(function(deltatime)
	if char.Parent == game.Workspace then
		if path ~= nil then
			for _, wayPoint in pairs(path:GetWaypoints()) do
				char.Humanoid:MoveTo(wayPoint.Position)
				--if wayPoint.Action == Enum.PathWaypointAction.Jump then
				--	char.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
				--end
				if target and target:FindFirstChild("Humanoid") and target:IsA("Model") and target ~= char and target.Humanoid.Health ~= 0 and (char.HumanoidRootPart.Position - target.HumanoidRootPart.Position).Magnitude <= 2 then
					char.Humanoid:MoveTo(target.HumanoidRootPart.Position)
					break
				end
			end
		end
	end
end)

could we just get the part where agent parameters are?

1 Like

task.spawn(function()
	while always do

		target = findNearestPlayer(true)
		
		if target and target:IsA("Model") and touching == false then
			humanoid.WalkSpeed = values.MaxWalk.Value
			PAUSEWALKING = false
		end
		
		if PAUSEWALKING == false then
			--if chasingplayer == false then
			--	WalkAnim:Stop()
			--end


			if not target then
				target = DecideWaypoint()
			end

			if chasingplayer == true and not walking then
				Idle:Stop()	
				Run:Play()
				walking = true
			end
			
			path = pathFinder:CreatePath() 

If i try adding any parameters to it, the character freezes in place

could we see the agent parameters?

I said i used the same ones in the document, and its still frozen when i try changing it to any number
image

try putting

char.Humanoid.MoveToFinished:Wait()

after

char.Humanoid:MoveTo(target.HumanoidRootPart.Position)

or

char.Humanoid:MoveTo(wayPoint.Position)

and see what it does, because when i didn’t add any delay it runned into walls, im still trying to learn scripting so idk if it will work or not and for the agent parameters im still looking at your script

Still frozen for me thirrrttyyyy

when you do path:ComputeAsync try using pcall(function() because it can fail and try using the default values for the agent parameters and try WITHOUT any Costs