Pathfinding to AI?
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:
01 | torso = script.Parent.Torso |
07 | function 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 |
14 | if (torso.Position-tor.Position).magnitude < (torso.Position-target.Torso.Position).magnitude then |
15 | print (plr.Name.. " is in range" ) |
16 | target = plr.Character |
19 | elseif (torso.Position-tor.Position).magnitude < = range then |
20 | print (plr.Name.. " is in range" ) |
21 | target = plr.Character |
30 | if hit.Parent ~ = nil and hit ~ = nil then |
31 | if hit.Parent:findFirstChild( "Humanoid" ) then |
32 | hit.Parent.Humanoid:TakeDamage(armDmg) |
36 | function hitTorso (hit) |
37 | if hit.Parent ~ = nil and hit ~ = nil then |
38 | if hit.Parent:findFirstChild( "Humanoid" ) then |
39 | hit.Parent.Humanoid:TakeDamage(torDmg) |
45 | script.Parent [ "Left Arm" ] .Touched:connect(hitArm) |
46 | script.Parent [ "Right Arm" ] .Touched:connect(hitArm) |
47 | script.Parent [ "Torso" ] .Touched:connect(hitTorso) |
53 | script.Parent.Zombie:MoveTo(target.Torso.Position,target.Torso) |