Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Our baseplate, or the terrain, if we have one [in our level, it is called "Cluster"]
- local basePlate = game.Workspace.Terrain
- -- Variable to store the bot
- local bot
- -- Torso of the bot
- local botTorso
- -- Humanoid of the bot
- local botHumanoid
- -- Direction the bot is moving in
- local botDirection
- -- Time taken for the bot to respawn
- local respawnTime = 4
- -- Garbage Collection service, which identifies the object to be removed after the given amount of time
- local debris = game:GetService("Debris")
- -- Part blocking the bot's path (right in front of his legs)
- local blockingPart
- -- The center of the bot's legs; used for determining if it should jump or not
- local botLegCenter
- -- Let the Bot wander!!!
- local maxWanderAngle = .75
- local wanderConeSize = 6
- local wanderTarget
- -- Prepare us a skelebot in advance [we'll clone all future skelebots from this one, so we don't spam the insert service with requests]
- -- First, we use the InsertService to get the model from ROBLOX
- local botPrototype = game:GetService("InsertService"):LoadAsset(53604463)
- -- now we check to see if we actually got something...
- if botPrototype then
- -- Everything is stored inside an extra container model
- -- Hence we need to extract the actual thing we want from inside that model
- -- So we use the GetChildren method to get all the objects in the container
- botPrototype = botPrototype:GetChildren()
- -- Our model is usually stored as the first object in the table
- -- NOTE: this could be different for some other types
- botPrototype = botPrototype[1]
- -- we'll name our bot Skelebomber
- botPrototype.Name = "Skelebomber"
- end
- -- Spawn Model
- function spawnBot()
- -- first check if we successfully got our bot from memory
- if botPrototype then
- -- then clone it!
- bot = botPrototype:Clone()
- -- Place the bot in the workspace
- bot.Parent = game.Workspace
- botHumanoid = bot:FindFirstChild("Humanoid")
- botTorso = bot:FindFirstChild("Torso")
- -- when the bot dies...
- if botHumanoid then botHumanoid.Died:connect(function()
- -- make the old bot get cleaned up after a bit
- debris:AddItem(bot, respawnTime)
- -- after a bit, spawn another one!
- wait(respawnTime)
- spawnBot()
- end)
- end
- -- place the bot to start with
- bot:MoveTo(Vector3.new(10, 125, 10), game.Workspace)
- end
- end
- -- function to tell whether bot is blocked by a part or not
- function botIsBlocked(botTarget)
- botDirection = (botTarget - botTorso.Position).unit * 2
- botLegCenter = botTorso.Position + Vector3.new(0, -2, 0)
- blockingPart = game.Workspace:FindPartOnRay(Ray.new(botLegCenter, botDirection), bot)
- return blockingPart
- end
- -- function to return where we should move the bot towards next (to make it randomly "wander")
- function getWanderTarget()
- math.random(tick())
- wanderAngle = (math.random() - 0.5) * maxWanderAngle
- rotatedLookVector = CFrame.Angles(0, wanderAngle, 0)*botTorso.CFrame.lookVector
- return (botTorso.Position + wanderConeSize*rotatedLookVector)
- end
- -- spawn our bot for the first time!
- spawnBot()
- -- below line of code keeps math.random always returning random values
- math.random(tick())
- -- Main Bot Loop!!
- while bot and botTorso and botHumanoid do
- -- find where to move to next
- wanderTarget = getWanderTarget()
- -- move the bot (and point it in the correct direction)
- botHumanoid:MoveTo(wanderTarget, basePlate)
- -- jump if we need to
- if botIsBlocked(wanderTarget) then
- botHumanoid.Jump = true
- end
- wait(0.125)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement