What is the limitations of this? How much do you need to know in order for it to work efficiently? What's the most efficient way to do this?
What I want to do is create AI's in one of my games that can locate where people are. How I was thinking of doing is creating paths for them to follow, Set paths that they can go on in order to attack people around each 'marker'. Each marker will represent where they can go with set lines made by each marker connecting. (Also is there any way to make it so they can only go 1 way on each line? for example a cliff you can't get back up, but you can jump down)
You don't need to explain things, but that would be nice, along with any wiki pages that would be helpful to read on this subject.
Well path finding is basically a way to get to point A to point B, also there is no "better method" out of all the methods, because they do the same thing.
So I went on studio's and took a zombie AI script and thought I could break it down trying to show you how an AI works, I guess you can make your own path find method but there all similar in someway.
local larm = script.Parent:FindFirstChild("Left Arm") local rarm = script.Parent:FindFirstChild("Right Arm") function findNearestTorso(pos) local list = game.Workspace:children() local torso = nil local dist = 1000 local temp = nil local human = nil local temp2 = nil for x = 1, #list do temp2 = list[x] if (temp2.className == "Model") and (temp2 ~= script.Parent) then temp = temp2:findFirstChild("Right Arm") human = temp2:findFirstChild("Humanoid") if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then if (temp.Position - pos).magnitude < dist then torso = temp dist = (temp.Position - pos).magnitude end end end end return torso end while true do wait(math.random(1,5)) local target = findNearestTorso(script.Parent.Torso.Position) if target ~= nil then script.Parent.Humanoid:MoveTo(target.Position, target) end end
So that's the script now let's break it down.
Part
local list = game.Workspace:children() local torso = nil -- This is defining if the torso that it's trying to find is equal to nil. local dist = 1000 -- MaxDistance that it can find the Torso. local temp = nil -- Will later be explained and so is the bottom. local human = nil local temp2 = nil
Part2
for x = 1, #list do -- For the number of children of workspace and was defined in Part1 temp2 = list[x] -- Saying that Temp2 is equal to every child of workspace if (temp2.className == "Model") and (temp2 ~= script.Parent) then -- Now it's only narrowing it down to models and if the child is not script's parent(zombie)
Part3(Final)
temp = temp2:findFirstChild("Right Arm") -- Finding right Arm of the player in workspace human = temp2:findFirstChild("Humanoid") -- Remember Temp2 is every model and a player's cahracter is a model the rest is self explanatory if (temp ~= nil) and (human ~= nil) and (human.Health > 0) then -- If the player right are is not equal and the humanoid is not equal to nil and the humanoid's health is greater then 0 if (temp.Position - pos).magnitude < dist then -- If the position of the players - zombie's magnitude is less then the dist torso = temp -- the torso now equals temp dist = (temp.Position - pos).magnitude -- the dist variable is now equal to zombie - player's magnitude. end end end end return torso -- returns it end
Hope this help's.
There's really no one answer to this question. It depends on how your maps are made, how your game plays (i.e. weapon design) and countless other things.
Your 'markers' are typically called Nodes, by the way.
Here are the four pathfinding pages on the wiki. I suggest you just go for it and ask for help here when you get stuck. :>