Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Pathfinding to AI?

Asked by 9 years ago

I have created a basic zombie off a tutorial but I need to redo movement into pathinding so that it does not like get stuck in front of objects so it can make it's way round the map to find the player and kill him for soul purpose of the game. However I don't know how to do this as it is very tricky. Please help!

Here is the current script:

01torso = script.Parent.Torso
02range = 50
03armDmg=5
04torDmg=10
05target = nil
06 
07function findNearestTarget()
08    plrs = game.Players:GetChildren()
09    for i,plr in ipairs (plrs) do
10        if plr.Character ~= nil then
11            if plr.Character:findFirstChild("Humanoid") and plr.Character.Humanoid.Health>0 then
12           tor = plr.Character.Torso
13            if target ~= nil then
14             if(torso.Position-tor.Position).magnitude < (torso.Position-target.Torso.Position).magnitude then
15                print(plr.Name.." is in range")
View all 55 lines...

1 answer

Log in to vote
0
Answered by
WVPII 5
9 years ago

First time using path finding service, so this may well need debugging.

01torso = script.Parent.Torso
02range = 50
03armDmg=5
04torDmg=10
05target = nil
06 
07function findNearestTarget()
08    plrs = game.Players:GetChildren()
09    for i,plr in ipairs (plrs) do
10        if plr.Character ~= nil then
11            if plr.Character:findFirstChild("Humanoid") and plr.Character.Humanoid.Health>0 then
12           tor = plr.Character.Torso
13            if target ~= nil then
14             if(torso.Position-tor.Position).magnitude < (torso.Position-target.Torso.Position).magnitude then
15                print(plr.Name.." is in range")
View all 60 lines...
Ad

Answer this question