Advertisement
KINGOFCOOL

Untitled

Jan 9th, 2015
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1. -- Our baseplate, or the terrain, if we have one [in our level, it is called "Cluster"]
  2. local basePlate = game.Workspace.Terrain
  3.  
  4. -- Variable to store the bot
  5. local bot
  6. -- Torso of the bot
  7. local botTorso
  8. -- Humanoid of the bot
  9. local botHumanoid
  10. -- Direction the bot is moving in
  11. local botDirection
  12. -- Time taken for the bot to respawn
  13. local respawnTime = 4
  14. -- Garbage Collection service, which identifies the object to be removed after the given amount of time
  15. local debris = game:GetService("Debris")
  16. -- Part blocking the bot's path (right in front of his legs)
  17. local blockingPart
  18. -- The center of the bot's legs; used for determining if it should jump or not
  19. local botLegCenter
  20.  
  21.  
  22. -- Let the Bot wander!!!
  23. local maxWanderAngle = .75
  24. local wanderConeSize = 6
  25. local wanderTarget
  26.  
  27. -- 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]
  28. -- First, we use the InsertService to get the model from ROBLOX
  29. local botPrototype = game:GetService("InsertService"):LoadAsset(53604463)
  30.  
  31. -- now we check to see if we actually got something...
  32. if botPrototype then
  33. -- Everything is stored inside an extra container model
  34. -- Hence we need to extract the actual thing we want from inside that model
  35. -- So we use the GetChildren method to get all the objects in the container
  36. botPrototype = botPrototype:GetChildren()
  37. -- Our model is usually stored as the first object in the table
  38. -- NOTE: this could be different for some other types
  39. botPrototype = botPrototype[1]
  40. -- we'll name our bot Skelebomber
  41. botPrototype.Name = "Skelebomber"
  42. end
  43.  
  44. -- Spawn Model
  45. function spawnBot()
  46. -- first check if we successfully got our bot from memory
  47. if botPrototype then
  48. -- then clone it!
  49. bot = botPrototype:Clone()
  50.  
  51. -- Place the bot in the workspace
  52. bot.Parent = game.Workspace
  53. botHumanoid = bot:FindFirstChild("Humanoid")
  54. botTorso = bot:FindFirstChild("Torso")
  55.  
  56. -- when the bot dies...
  57. if botHumanoid then botHumanoid.Died:connect(function()
  58. -- make the old bot get cleaned up after a bit
  59. debris:AddItem(bot, respawnTime)
  60.  
  61. -- after a bit, spawn another one!
  62. wait(respawnTime)
  63. spawnBot()
  64. end)
  65. end
  66.  
  67. -- place the bot to start with
  68. bot:MoveTo(Vector3.new(10, 125, 10), game.Workspace)
  69. end
  70. end
  71.  
  72. -- function to tell whether bot is blocked by a part or not
  73. function botIsBlocked(botTarget)
  74. botDirection = (botTarget - botTorso.Position).unit * 2
  75. botLegCenter = botTorso.Position + Vector3.new(0, -2, 0)
  76. blockingPart = game.Workspace:FindPartOnRay(Ray.new(botLegCenter, botDirection), bot)
  77. return blockingPart
  78. end
  79.  
  80. -- function to return where we should move the bot towards next (to make it randomly "wander")
  81. function getWanderTarget()
  82. math.random(tick())
  83. wanderAngle = (math.random() - 0.5) * maxWanderAngle
  84. rotatedLookVector = CFrame.Angles(0, wanderAngle, 0)*botTorso.CFrame.lookVector
  85. return (botTorso.Position + wanderConeSize*rotatedLookVector)
  86. end
  87.  
  88. -- spawn our bot for the first time!
  89. spawnBot()
  90.  
  91. -- below line of code keeps math.random always returning random values
  92. math.random(tick())
  93.  
  94. -- Main Bot Loop!!
  95. while bot and botTorso and botHumanoid do
  96. -- find where to move to next
  97. wanderTarget = getWanderTarget()
  98.  
  99. -- move the bot (and point it in the correct direction)
  100. botHumanoid:MoveTo(wanderTarget, basePlate)
  101.  
  102. -- jump if we need to
  103. if botIsBlocked(wanderTarget) then
  104. botHumanoid.Jump = true
  105. end
  106.  
  107. wait(0.125)
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement