Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Converted with ttyyuu12345's model to script plugin v4
- function sandbox(var,func)
- local env = getfenv(func)
- local newenv = setmetatable({},{
- __index = function(self,k)
- if k=="script" then
- return var
- else
- return env[k]
- end
- end,
- })
- setfenv(func,newenv)
- return func
- end
- cors = {}
- mas = Instance.new("Model",game:GetService("Lighting"))
- Model0 = Instance.new("Model")
- Script1 = Instance.new("Script")
- Script2 = Instance.new("Script")
- Model3 = Instance.new("Model")
- Part4 = Instance.new("Part")
- Part5 = Instance.new("Part")
- Part6 = Instance.new("Part")
- Script7 = Instance.new("Script")
- Part8 = Instance.new("Part")
- Part9 = Instance.new("Part")
- Part10 = Instance.new("Part")
- Part11 = Instance.new("Part")
- Part12 = Instance.new("Part")
- Part13 = Instance.new("Part")
- SpecialMesh14 = Instance.new("SpecialMesh")
- Decal15 = Instance.new("Decal")
- Script16 = Instance.new("Script")
- Model0.Parent = mas
- Script1.Name = "Tutorial"
- Script1.Parent = Model0
- table.insert(cors,sandbox(Script1,function()
- -- Hello everyone, ImaBoss838 here. This is a small read me/tutorial on how to set up Redditor's pathfinding zombie ai.
- -- Lets start off with the basics:
- -- *You can edit the detection distance on the AI in the controller script, i've highlighted the line.
- -- *The "Spawner" script is just kind of a duplicator script, it duplicates the zombie and respawns it.
- -- *Inside the "Spawner" script there is the model, aka, the zombie AI. You can copy it and paste it as you like.
- -- *Inside the Zombie AI there is a script, edit the stats there. (The ones I tell you that you can edit, its marked in the script)
- -- Now, with that out of the way, its not really much else to say, right now you cant tweak as much on this AI, unless you know what you're doing.
- -- Happy zombie slaying!
- end))
- Script2.Name = "Spawner"
- Script2.Parent = Model0
- table.insert(cors,sandbox(Script2,function()
- local model = script:GetChildren()[1]:clone()
- script.ChildRemoved:connect(function()
- for i = 1, 25 - #script:GetChildren() do
- local m = model:clone()
- m.Parent = script
- m:MoveTo(Vector3.new(math.random() * 200-100, 5, math.random() * 200-100))
- end
- end)
- script:GetChildren()[1]:Destroy()
- end))
- Model3.Name = "Zombie A.I"
- Model3.Parent = Script2
- Part4.Name = "Right Leg"
- Part4.Parent = Model3
- Part4.CFrame = CFrame.new(-12.199996, 1.90001094, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part4.Position = Vector3.new(-12.199996, 1.90001094, -16.1000061)
- Part4.Color = Color3.new(0, 0.560784, 0.611765)
- Part4.Transparency = 1
- Part4.Size = Vector3.new(1, 1, 1)
- Part4.Anchored = true
- Part4.BottomSurface = Enum.SurfaceType.Smooth
- Part4.BrickColor = BrickColor.new("Bright bluish green")
- Part4.Locked = true
- Part4.TopSurface = Enum.SurfaceType.Smooth
- Part4.brickColor = BrickColor.new("Bright bluish green")
- Part4.FormFactor = Enum.FormFactor.Custom
- Part4.formFactor = Enum.FormFactor.Custom
- Part5.Name = "Torso"
- Part5.Parent = Model3
- Part5.CFrame = CFrame.new(-12.199996, 3.00001192, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part5.Position = Vector3.new(-12.199996, 3.00001192, -16.1000061)
- Part5.Color = Color3.new(0.388235, 0.372549, 0.384314)
- Part5.Transparency = 1
- Part5.Size = Vector3.new(2, 2, 2)
- Part5.Anchored = true
- Part5.BottomSurface = Enum.SurfaceType.Smooth
- Part5.BrickColor = BrickColor.new("Dark stone grey")
- Part5.Friction = 0
- Part5.Locked = true
- Part5.TopSurface = Enum.SurfaceType.Smooth
- Part5.brickColor = BrickColor.new("Dark stone grey")
- Part5.FormFactor = Enum.FormFactor.Symmetric
- Part5.formFactor = Enum.FormFactor.Symmetric
- Part5.Shape = Enum.PartType.Ball
- Part6.Name = "Head"
- Part6.Parent = Model3
- Part6.CFrame = CFrame.new(-12.199996, 4.50000381, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part6.Position = Vector3.new(-12.199996, 4.50000381, -16.1000061)
- Part6.Color = Color3.new(0, 0.560784, 0.611765)
- Part6.Transparency = 1
- Part6.Size = Vector3.new(1, 1, 1)
- Part6.Anchored = true
- Part6.BottomSurface = Enum.SurfaceType.Smooth
- Part6.BrickColor = BrickColor.new("Bright bluish green")
- Part6.FrontSurface = Enum.SurfaceType.Hinge
- Part6.Locked = true
- Part6.TopSurface = Enum.SurfaceType.Smooth
- Part6.brickColor = BrickColor.new("Bright bluish green")
- Part6.FormFactor = Enum.FormFactor.Custom
- Part6.formFactor = Enum.FormFactor.Custom
- Script7.Parent = Model3
- table.insert(cors,sandbox(Script7,function()
- local ai = {}
- ai.Model = script.Parent
- -- The zombies memory. (You can edit these stats)
- local goalPos
- local lastAttack = time()
- local attackTime = .3
- local atkDamage = 5
- local goalHumanoid
- local running
- local running2
- local crawling
- local limp = {}
- for i = 1, 10 do
- limp[i] = (math.random() * 2) - 1
- end
- -- Global functions. (I wouldnt mess with this..)
- ai.Move = function(loc, mustSee, humanoid)
- goalHumanoid = humanoid
- if goalPos then
- goalPos = loc
- else
- goalPos = loc
- Spawn(function()
- ai.State = "Tracking"
- local lastGoal
- local lastTime = time()
- while goalPos and ai.Humanoid do
- local gp = goalPos
- if pcall(function() return goalPos.X end) then
- elseif goalPos:IsA("BasePart") then
- gp = (ai.canSee(goalPos) or not mustSee) and goalPos.Position or nil
- lastTime = time()
- elseif goalPos:IsA("Model") then
- gp = nil
- for _, bodyPart in pairs(goalPos:GetChildren()) do
- if bodyPart:IsA("BasePart") and (ai.canSee(bodyPart) or not mustSee) then
- gp = goalPos:GetModelCFrame().p
- lastTime = time()
- break
- end
- end
- end
- lastGoal = gp and humanoid and gp + (gp - ai.Model.Torso.Position).unit * 10 or gp or lastGoal or ai.Model.Torso.Position
- if (goalHumanoid and goalHumanoid.Health <= 0) or (not goalHumanoid and (ai.Model.Torso.Position - lastGoal).magnitude < 3) or time() - lastTime > 3 then
- goalPos = nil
- else
- ai.Humanoid.Jump = objAhead(lastGoal)
- ai.Humanoid:MoveTo(lastGoal, workspace.Terrain)
- if goalHumanoid and ((ai.Model.Torso.Position - goalPos:GetModelCFrame().p) * Vector3.new(1,.5,1)).magnitude < 3 and time() - lastAttack > attackTime then
- attack(goalHumanoid)
- end
- end
- wait(.1)
- end
- if ai then
- ai.State = "Idle"
- end
- end)
- end
- end
- --local functions
- function weld(a, b, c0, c1)
- local w = Instance.new("Weld", a)
- w.Part0 = a
- w.Part1 = b
- if c0 then w.C0 = c0 end
- if c1 then w.C1 = c1 end
- return w
- end
- function setHeight(n)
- if ai.Model:findFirstChild("Right Leg") then
- ai.Model["Right Leg"]:BreakJoints()
- ai.Model["Right Leg"].Size = ai.Model["Right Leg"].Size * Vector3.new(1,0,1) + Vector3.new(0, math.max(0.2, n or 0),0)
- weld(ai.Model.Torso, ai.Model["Right Leg"], CFrame.new(0, -n + ai.Model["Right Leg"].Size.Y/2 - ai.Model.Torso.Size.Y/2,0))
- end
- if m and ai.Model:findFirstChild("Head") then
- ai.Model.Head:BreakJoints()
- weld(ai.Model.Torso, ai.Model.Head, CFrame.new(0, m - ai.Model.Head.Size.Y/2 + ai.Model.Torso.Size.Y/2,0))
- end
- end
- function objAhead(loc)
- if not _G.AntiJumpCache then
- _G.AntiJumpCache = {}
- end
- local ray = Ray.new(ai.Model.Torso.Position, ((loc - ai.Model.Torso.Position) * Vector3.new(1,0,1)).unit * 5)
- local obj, pos = workspace:FindPartOnRayWithIgnoreList(ray, _G.AntiJumpCache)
- if obj then
- if not obj.CanCollide then
- table.insert(_G.AntiJumpCache, obj)
- elseif obj.Parent:findFirstChild("Humanoid") then
- table.insert(_G.AntiJumpCache, obj.Parent)
- else
- return true
- end
- --add to cache if necessary, otherwise recurse
- return objAhead(loc)
- end
- end
- function ai.canSee(obj, fov)
- local direction = (obj.Position - ai.Model.Head.Position).unit
- if fov and direction:Dot(ai.Model.Head.CFrame.lookVector) < math.cos(math.rad(fov)) then
- return false
- end
- local ray = Ray.new(ai.Model.Head.Position, direction * 900)
- local hit, pos = workspace:FindPartOnRayWithIgnoreList(ray, {ai.Model})
- if hit then
- --add to cache if transparent?
- if hit == obj then
- return true
- end
- end
- end
- function attack(hum)
- print("pow")
- lastAttack = time()
- hum:TakeDamage(atkDamage)
- end
- function initialize()
- for _, obj in pairs(ai.Model:GetChildren()) do
- if obj:IsA("BasePart") then
- obj.Anchored = false
- end
- end
- setHeight(2, 1)
- ai.tWeld = weld(ai.Model.Torso, ai.Model.torso, CFrame.new(0,-1,0), CFrame.new(0,-1,0) * CFrame.Angles(math.rad(45),0,0))
- ai.hWeld = weld(ai.Model.torso, ai.Model.head2, CFrame.new(0,.8,0), CFrame.new(0,-.6,0) * CFrame.Angles(math.rad(-22.5),0,0))
- ai.lWeld1 = weld(ai.Model.torso, ai.Model.leftLeg, CFrame.new(-0.5,-1,0), CFrame.new(0,1,0) * CFrame.Angles(math.rad(-45),0,0))
- ai.lWeld2 = weld(ai.Model.torso, ai.Model.rightLeg, CFrame.new(0.5,-1,0), CFrame.new(0,1,0) * CFrame.Angles(math.rad(-45),0,0))
- ai.aWeld1 = weld(ai.Model.torso, ai.Model.leftArm, CFrame.new(-1,0.5,0), CFrame.new(0.5,0.5,0) * CFrame.Angles(math.rad(-45),0,0))
- ai.aWeld2 = weld(ai.Model.torso, ai.Model.rightArm, CFrame.new(1,0.5,0), CFrame.new(-0.5,0.5,0) * CFrame.Angles(math.rad(-45),0,0))
- ai.HWeld = weld(ai.Model.Torso, ai.Model.Head)
- anim(math.rad(20),0,0)
- ai.Humanoid = Instance.new("Humanoid", ai.Model)
- ai.Humanoid.WalkSpeed = math.random(8,14) + math.max(0, math.random(-5,3))
- ai.State = "Idle"
- ai.Model.ChildRemoved:connect(delete)
- ai.Humanoid.Died:connect(delete)
- ai.Humanoid.Running:connect(animate)
- table.insert(_G.aiTable, ai)
- end
- function delete()
- wait(0)
- if not ai.Humanoid or not (ai.Humanoid.Health > 0) or not ai.Model:findFirstChild("Torso") or not ai.Model:FindFirstChild("Head") or not ai.Model:FindFirstChild("head2") then
- for i, a in pairs(_G.aiTable) do
- if a == ai then
- table.remove(_G.aiTable, i)
- end
- end
- ai.Model:BreakJoints()
- game.Debris:AddItem(ai.Model, 3)
- for i, obj in pairs(ai.Model:GetChildren()) do
- if obj:IsA("BasePart") and obj.Transparency ~= 1 then
- obj.CanCollide = true
- elseif obj ~= script then
- obj:Destroy()
- end
- end
- ai = nil
- goalPos = nil
- elseif not (ai.Model:FindFirstChild("leftLeg") and ai.Model:FindFirstChild("rightLeg")) and not crawling then
- crawl()
- end
- if ai and crawling and not (ai.Model:FindFirstChild("leftArm") and ai.Model:FindFirstChild("rightArm")) then
- ai.Humanoid.Health = 0
- end
- end
- function animate(a)
- if not running2 then
- running = a > 0
- if running then
- Spawn(function()
- running2 = true
- local start = time()
- while running do
- wait(0)
- local cycle = (tick() - start) * 5
- local tPitch = math.rad(25 + math.cos(cycle * 2) * -5)
- local tRoll = math.rad(math.sin(cycle) * 10)
- local lPitch = math.rad(math.sin(cycle) * 45)
- anim(tPitch, tRoll, lPitch)
- end
- running2 = false
- anim(math.rad(20),0,0)
- end)
- end
- else
- running = a > 0
- end
- end
- function anim(tPitch, tRoll, lPitch)
- if not ai then return end
- local crawlMod = crawling and math.rad(50) or 0
- local crawlMod2 = crawling and 4 or 1
- local attackMod = (attackTime - math.min(attackTime,(time() - lastAttack)))/attackTime * math.rad(140)
- lPitch2 = crawling and lPitch / 3 or lPitch
- if ai.tWeld then
- ai.tWeld.C1 = CFrame.new(0,-1,0) * CFrame.Angles(tPitch + crawlMod,0,tRoll + limp[1] * .4)
- end
- if ai.hWeld then
- ai.hWeld.C1 = CFrame.new(0,-0.6,0) * CFrame.Angles(-tPitch/2,0,tRoll + limp[2] * .4)
- end
- if ai.lWeld1 then
- ai.lWeld1.C1 = CFrame.new(0,1,0) * CFrame.Angles(lPitch2 - tPitch + crawlMod + limp[3] * .4,0,-tRoll - limp[1] * .4)
- end
- if ai.lWeld2 then
- ai.lWeld2.C1 = CFrame.new(0,1,0) * CFrame.Angles(-lPitch2 - tPitch + crawlMod + limp[4] * .4,0,-tRoll - limp[1] * .4)
- end
- if ai.aWeld1 then
- ai.aWeld1.C1 = CFrame.new(0.5,0.5,0) * CFrame.Angles(0,0, crawlMod/2) * CFrame.Angles(lPitch * math.abs(limp[5]) * -0.4 * crawlMod2 - tPitch - crawlMod - attackMod + limp[5] * .2, 0, -tRoll - limp[1] * .4)
- end
- if ai.aWeld2 then
- ai.aWeld2.C1 = CFrame.new(-0.5,0.5,0) * CFrame.Angles(0,0, -crawlMod/2) * CFrame.Angles(lPitch * math.abs(limp[6]) * 0.4 * crawlMod2 - tPitch - crawlMod - attackMod + limp[6] * .2, 0, -tRoll - limp[1] * .4)
- end
- if ai.HWeld and ai.Model:findFirstChild("head2") then
- ai.HWeld.C0 = ai.Model.Torso.CFrame:toObjectSpace(ai.Model.head2.CFrame)
- end
- end
- function crawl()
- crawling = true
- setHeight(0,0)
- ai.Humanoid.WalkSpeed = math.random(4, 6)
- end
- while not _G.aiTable do
- wait(0)
- end
- initialize()
- end))
- Part8.Name = "rightLeg"
- Part8.Parent = Model3
- Part8.CFrame = CFrame.new(-11.699996, 1.00001299, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part8.Position = Vector3.new(-11.699996, 1.00001299, -16.1000061)
- Part8.Color = Color3.new(1, 0, 0)
- Part8.Size = Vector3.new(1, 2, 0.99999994)
- Part8.Anchored = true
- Part8.BottomSurface = Enum.SurfaceType.Smooth
- Part8.BrickColor = BrickColor.new("Really red")
- Part8.CanCollide = false
- Part8.TopSurface = Enum.SurfaceType.Smooth
- Part8.brickColor = BrickColor.new("Really red")
- Part8.FormFactor = Enum.FormFactor.Custom
- Part8.formFactor = Enum.FormFactor.Custom
- Part9.Name = "leftLeg"
- Part9.Parent = Model3
- Part9.CFrame = CFrame.new(-12.699996, 1.00001299, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part9.Position = Vector3.new(-12.699996, 1.00001299, -16.1000061)
- Part9.Color = Color3.new(1, 0, 0)
- Part9.Size = Vector3.new(1, 2, 0.99999994)
- Part9.Anchored = true
- Part9.BottomSurface = Enum.SurfaceType.Smooth
- Part9.BrickColor = BrickColor.new("Really red")
- Part9.CanCollide = false
- Part9.TopSurface = Enum.SurfaceType.Smooth
- Part9.brickColor = BrickColor.new("Really red")
- Part9.FormFactor = Enum.FormFactor.Custom
- Part9.formFactor = Enum.FormFactor.Custom
- Part10.Name = "leftArm"
- Part10.Parent = Model3
- Part10.CFrame = CFrame.new(-13.7000055, 3.00001192, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part10.Position = Vector3.new(-13.7000055, 3.00001192, -16.1000061)
- Part10.Color = Color3.new(1, 0, 0)
- Part10.Size = Vector3.new(1, 2, 0.99999994)
- Part10.Anchored = true
- Part10.BottomSurface = Enum.SurfaceType.Smooth
- Part10.BrickColor = BrickColor.new("Really red")
- Part10.CanCollide = false
- Part10.TopSurface = Enum.SurfaceType.Smooth
- Part10.brickColor = BrickColor.new("Really red")
- Part10.FormFactor = Enum.FormFactor.Custom
- Part10.formFactor = Enum.FormFactor.Custom
- Part11.Name = "torso"
- Part11.Parent = Model3
- Part11.CFrame = CFrame.new(-12.199996, 3.00001192, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part11.Position = Vector3.new(-12.199996, 3.00001192, -16.1000061)
- Part11.Color = Color3.new(1, 0, 0)
- Part11.Size = Vector3.new(2, 2, 0.99999994)
- Part11.Anchored = true
- Part11.BottomSurface = Enum.SurfaceType.Smooth
- Part11.BrickColor = BrickColor.new("Really red")
- Part11.CanCollide = false
- Part11.Locked = true
- Part11.TopSurface = Enum.SurfaceType.Smooth
- Part11.brickColor = BrickColor.new("Really red")
- Part11.FormFactor = Enum.FormFactor.Custom
- Part11.formFactor = Enum.FormFactor.Custom
- Part12.Name = "rightArm"
- Part12.Parent = Model3
- Part12.CFrame = CFrame.new(-10.699996, 3.00001192, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part12.Position = Vector3.new(-10.699996, 3.00001192, -16.1000061)
- Part12.Color = Color3.new(1, 0, 0)
- Part12.Size = Vector3.new(1, 2, 0.99999994)
- Part12.Anchored = true
- Part12.BottomSurface = Enum.SurfaceType.Smooth
- Part12.BrickColor = BrickColor.new("Really red")
- Part12.CanCollide = false
- Part12.TopSurface = Enum.SurfaceType.Smooth
- Part12.brickColor = BrickColor.new("Really red")
- Part12.FormFactor = Enum.FormFactor.Custom
- Part12.formFactor = Enum.FormFactor.Custom
- Part13.Name = "head2"
- Part13.Parent = Model3
- Part13.CFrame = CFrame.new(-12.199996, 4.50000381, -16.1000061, 1, 0, 0, 0, 1, 0, 0, 0, 1)
- Part13.Position = Vector3.new(-12.199996, 4.50000381, -16.1000061)
- Part13.Color = Color3.new(1, 0, 0)
- Part13.Size = Vector3.new(1, 1, 1)
- Part13.Anchored = true
- Part13.BottomSurface = Enum.SurfaceType.Smooth
- Part13.BrickColor = BrickColor.new("Really red")
- Part13.CanCollide = false
- Part13.TopSurface = Enum.SurfaceType.Smooth
- Part13.brickColor = BrickColor.new("Really red")
- Part13.FormFactor = Enum.FormFactor.Custom
- Part13.formFactor = Enum.FormFactor.Custom
- SpecialMesh14.Parent = Part13
- SpecialMesh14.Scale = Vector3.new(1.39999998, 1.39999998, 1.39999998)
- Decal15.Name = "Rage Face"
- Decal15.Parent = Part13
- Decal15.Texture = "http://www.roblox.com/asset/?id=109676489"
- Script16.Name = "Controller"
- Script16.Parent = Model0
- table.insert(cors,sandbox(Script16,function()
- _G.aiTable = {}
- while wait(.1) do
- for i, ai in pairs(_G.aiTable) do
- if ai ~= nil and ai.State == "Idle" then
- local closestChar
- local closestDist = 200 -- Edit this value, it changes how close you have to be to the zombie for it to attack or "see" you.
- local pos = ai.Model:GetModelCFrame().p
- for j, player in pairs(game.Players:GetPlayers()) do
- if player.Character and player.Character:findFirstChild("Humanoid") and player.Character.Humanoid.Health > 0 then
- local dist = (player.Character:GetModelCFrame().p - pos).magnitude
- if dist <= closestDist then
- for _, obj in pairs(player.Character:GetChildren()) do
- if obj:IsA("BasePart") and (ai.canSee(obj, 85) or ai.canSee(obj) and dist <= 10)then
- closestChar = player.Character
- closestDist = dist
- break
- end
- end
- end
- end
- end
- if closestChar then
- ai.Move(closestChar, true, closestChar:findFirstChild("Humanoid"))
- elseif math.random() > 0.8 then
- local dir = CFrame.Angles(0,math.random() * math.pi * 2,0).lookVector
- local _, pos = workspace:FindPartOnRay(Ray.new(ai.Model:GetModelCFrame().p, dir * math.random(10,20)), ai.Model)
- pos = pos - dir * 5
- ai.Move(pos)
- end
- end
- end
- end
- end))
- for i,v in pairs(mas:GetChildren()) do
- v.Parent = script
- pcall(function() v:MakeJoints() end)
- end
- mas:Destroy()
- for i,v in pairs(cors) do
- spawn(function()
- pcall(v)
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment