wood1111

dwd

Jan 14th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.20 KB | None | 0 0
  1. CN, CA, V3, U2, C3, BN = CFrame.new, CFrame.Angles, Vector3.new, UDim2.new, Color3.new, BrickColor.new
  2. function new(instanceType, parent)
  3. return function(configuration)
  4. local newInstance = Instance.new(instanceType, parent)
  5. if newInstance:IsA("BasePart") then
  6. newInstance.TopSurface = 0
  7. newInstance.BottomSurface = 0
  8. if not newInstance:IsA("CornerWedgePart") then
  9. newInstance.FormFactor = 3
  10. end
  11. newInstance.Material = "Granite"
  12. newInstance.BrickColor = BN("Medium stone grey")
  13. newInstance.Locked = true
  14. end
  15. for property, value in pairs(configuration) do
  16. if type(value) == "function" then
  17. newInstance[property]:connect(value)
  18. else
  19. newInstance[property] = value
  20. end
  21. end
  22. if configuration["CFrame"] then
  23. newInstance.CFrame = configuration["CFrame"]
  24. end
  25. return newInstance
  26. end
  27. end
  28. function QuaternionFromCFrame(cf)
  29. local mx, my, mz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = cf:components()
  30. local trace = m00+m11+m22
  31. if trace > 0 then
  32. local s = math.sqrt(1+trace)
  33. local recip = 0.5/s
  34. return (m21-m12)*recip, (m02-m20)*recip, (m10-m01)*recip, s*0.5
  35. else
  36. local i = 0
  37. if m11 > m00 then
  38. i = 1
  39. end
  40. if m22 > (i == 0 and m00 or m11) then
  41. i = 2
  42. end
  43. if i == 0 then
  44. local s = math.sqrt(m00-m11-m22+1)
  45. local recip = 0.5/s
  46. return 0.5*s, (m10+m01)*recip, (m20+m02)*recip, (m21-m12)*recip
  47. elseif i == 1 then
  48. local s = math.sqrt(m11-m22-m00+1)
  49. local recip = 0.5/s
  50. return (m01+m10)*recip, 0.5*s, (m21+m12)*recip, (m02-m20)*recip
  51. elseif i == 2 then
  52. local s = math.sqrt(m22-m00-m11+1)
  53. local recip = 0.5/s
  54. return (m02+m20)*recip, (m12+m21)*recip, 0.5*s, (m10-m01)*recip
  55. end
  56. end
  57. end
  58. function QuaternionToCFrame(px, py, pz, x, y, z, w)
  59. local xs, ys, zs = x+x, y+y, z+z
  60. local wx, wy, wz = w*xs, w*ys, w*zs
  61. local xx = x*xs
  62. local xy = x*ys
  63. local xz = x*zs
  64. local yy = y*ys
  65. local yz = y*zs
  66. local zz = z*zs
  67. return CFrame.new(px, py, pz, 1-(yy+zz), xy-wz, xz+wy, xy+wz, 1-(xx+zz), yz-wx, xz-wy, yz+wx, 1-(xx+yy))
  68. end
  69. function QuaternionSlerp(a, b, t)
  70. local cosTheta = a[1]*b[1]+a[2]*b[2]+a[3]*b[3]+a[4]*b[4]
  71. local startInterp, finishInterp;
  72. if cosTheta >= 0.0001 then
  73. if (1-cosTheta) > 0.0001 then
  74. local theta = math.acos(cosTheta)
  75. local invSinTheta = 1/math.sin(theta)
  76. startInterp = math.sin((1-t)*theta)*invSinTheta
  77. finishInterp = math.sin(t*theta)*invSinTheta
  78. else
  79. startInterp = 1-t
  80. finishInterp = t
  81. end
  82. else
  83. if (1+cosTheta) > 0.0001 then
  84. local theta = math.acos(-cosTheta)
  85. local invSinTheta = 1/math.sin(theta)
  86. startInterp = math.sin((t-1)*theta)*invSinTheta
  87. finishInterp = math.sin(t*theta)*invSinTheta
  88. else
  89. startInterp = t-1
  90. finishInterp = t
  91. end
  92. end
  93. return a[1]*startInterp+b[1]*finishInterp, a[2]*startInterp+b[2]*finishInterp, a[3]*startInterp+b[3]*finishInterp, a[4]*startInterp+b[4]*finishInterp
  94. end
  95. function Lerp(a, b, t)
  96. local qa = {QuaternionFromCFrame(a)}
  97. local qb = {QuaternionFromCFrame(b)}
  98. local ax, ay, az = a.x, a.y, a.z
  99. local bx, by, bz = b.x, b.y, b.z
  100. local _t = 1-t
  101. return QuaternionToCFrame(_t*ax+t*bx, _t*ay+t*by, _t*az+t*bz, QuaternionSlerp(qa, qb, t))
  102. end
  103.  
  104. for _, Obj in pairs(Workspace:GetChildren()) do
  105. if Obj.Name == "Awesome scary spider" then
  106. Obj:Destroy()
  107. end
  108. end
  109.  
  110. Offset = V3(25, -0.9, 25)
  111. SpiderColor = "Maroon"
  112.  
  113. Spider = new("Model", game.Players.LocalPlayer.Character){Name = "Awesome scary spider"}
  114. Platform = new("Part", Spider){Size = V3(30, 1, 30), BrickColor = BN("Really red"), Transparency = 1, CanCollide = true}
  115.  
  116. Torso = new("Part", Spider){Size = V3(4, 4, 6), Name = "Torso", BrickColor = BN(SpiderColor), Transparency = 1}
  117. new("BlockMesh", Torso){Scale = V3(1, 1, 1)}
  118. new("Motor6D", Platform){Part0 = Platform, Part1 = Torso, C0 = CN(0, 5, 0)}
  119. TorsoA = new("Part", Spider){Size = V3(4, 5, 3), BrickColor = BN(SpiderColor)}
  120. new("SpecialMesh", TorsoA){MeshType = "Sphere", Scale = V3(1.5, 1.5, 1.5)}
  121. new("Motor6D", Torso){Part0 = Torso, Part1 = TorsoA, C0 = CA(math.rad(90), 0, 0)}
  122.  
  123. Head = new("Part", Spider){Size = V3(2, 2, 2), Name = "Head", BrickColor = BN(SpiderColor), Transparency = 1}
  124. new("SpecialMesh", Head){MeshType = "Sphere", Scale = V3(1.5, 1.5, 1.5)}
  125. Neck = new("Motor6D", Torso){Part0 = Torso, Part1 = Head, C0 = CN(0, 0, -4), Name = "Neck"}
  126.  
  127. FakeHead = new("Part", Spider){Size = V3(2, 2, 2), BrickColor = BN(SpiderColor)}
  128. new("SpecialMesh", FakeHead){MeshType = "Sphere", Scale = V3(1.5, 1.5, 1.5)}
  129. new("Motor6D", Head){Part0 = Head, Part1 = FakeHead, C0 = CN()}
  130.  
  131. RightEye = new("Part", Spider){Size = V3(0.5, 0.5, 0.5), BrickColor = BN("White")}
  132. new("SpecialMesh", RightEye){MeshType = "Sphere", Scale = V3(1, 1, 1)}
  133. new("Motor6D", Head){Part0 = Head, Part1 = RightEye, C0 = CN(0.5, 0.25, -1.25)}
  134.  
  135. LeftEye = new("Part", Spider){Size = V3(0.5, 0.5, 0.5), BrickColor = BN("White")}
  136. new("SpecialMesh", LeftEye){MeshType = "Sphere", Scale = V3(1, 1, 1)}
  137. new("Motor6D", Head){Part0 = Head, Part1 = LeftEye, C0 = CN(-0.5, 0.25, -1.25)}
  138.  
  139. Torso2 = new("Part", Spider){Size = V3(5.5, 4.3, 7), BrickColor = BN(SpiderColor)}
  140. new("Motor6D", Torso){Part0 = Torso, Part1 = Torso2, C0 = CN(0, 0, 7)}
  141. new("SpecialMesh", Torso2){MeshType = "Sphere", Scale = V3(1.5, 1.5, 1.5)}
  142.  
  143. RightLegs = {}
  144. LeftLegs = {}
  145.  
  146. for L = 1, 4 do
  147. local RightLeg = new("Part", Spider){Size = V3(1, 5, 1), BrickColor = BN(SpiderColor)}
  148. new("CylinderMesh", RightLeg){Scale = V3(1, 1, 1)}
  149. new("Motor6D", RightLeg){Part0 = Torso, Part1 = RightLeg, C0 = CN(1.5, -1.5, -2+L)*CA(0, math.rad(45-L*15), math.rad(-60))*CN(0, 2.5, 0)}
  150. local RightLeg2 = new("Part", Spider){Size = V3(0.8, 5, 0.8), BrickColor = BN(SpiderColor)}
  151. new("CylinderMesh", RightLeg2){Scale = V3(1, 1, 1)}
  152. new("Motor6D", RightLeg2){Part0 = RightLeg, Part1 = RightLeg2, C0 = CN(0, 2.1, 0)*CA(0, 0, math.rad(-45))*CN(0, 2.5, 0)}
  153. local RightLeg3 = new("Part", Spider){Size = V3(0.6, 5, 0.6), BrickColor = BN(SpiderColor)}
  154. new("CylinderMesh", RightLeg3){Scale = V3(1, 1, 1)}
  155. new("Motor6D", RightLeg3){Part0 = RightLeg2, Part1 = RightLeg3, C0 = CN(0, 2.2, 0)*CA(0, 0, math.rad(-75))*CN(0, 2.5, 0)}
  156. table.insert(RightLegs, {RightLeg, RightLeg2, RightLeg3})
  157.  
  158. local LeftLeg = new("Part", Spider){Size = V3(1, 5, 1), BrickColor = BN(SpiderColor)}
  159. new("CylinderMesh", LeftLeg){Scale = V3(1, 1, 1)}
  160. new("Motor6D", LeftLeg){Part0 = Torso, Part1 = LeftLeg, C0 = CN(-1.5, -1.5, -2+L)*CA(0, math.rad(-45+L*15), math.rad(60))*CN(0, 2.5, 0)}
  161. local LeftLeg2 = new("Part", Spider){Size = V3(0.8, 5, 0.8), BrickColor = BN(SpiderColor)}
  162. new("CylinderMesh", LeftLeg2){Scale = V3(1, 1, 1)}
  163. new("Motor6D", LeftLeg2){Part0 = LeftLeg, Part1 = LeftLeg2, C0 = CN(0, 2.1, 0)*CA(0, 0, math.rad(45))*CN(0, 2.5, 0)}
  164. local LeftLeg3 = new("Part", Spider){Size = V3(0.6, 5, 0.6), BrickColor = BN(SpiderColor)}
  165. new("CylinderMesh", LeftLeg3){Scale = V3(1, 1, 1)}
  166. new("Motor6D", LeftLeg3){Part0 = LeftLeg2, Part1 = LeftLeg3, C0 = CN(0, 2.2, 0)*CA(0, 0, math.rad(75))*CN(0, 2.5, 0)}
  167. table.insert(LeftLegs, {LeftLeg, LeftLeg2, LeftLeg3})
  168. end
  169.  
  170. SpiderHumanoid = new("Humanoid", Spider){WalkSpeed = 30}
  171. Spider:MakeJoints()
  172. Platform.CFrame = CN(Offset)
  173.  
  174. SpiderVelocity = new("BodyVelocity", Platform){maxForce = V3(1/0, 1/0, 1/0)}
  175. SpiderGyro = new("BodyGyro", Platform){maxTorque = V3(1/0, 1/0, 1/0), P = 1000, D = 100}
  176.  
  177. --Now, on to the fun stuffs..
  178.  
  179. Player = Game:GetService("Players").LocalPlayer
  180. Mouse = Player:GetMouse()
  181. UserInputService = Game:GetService("UserInputService")
  182. Camera = Workspace.CurrentCamera
  183.  
  184. --Camera.CameraType = "Scriptable"
  185.  
  186. Character = Player.Character
  187. Character:WaitForChild("Animate"):Destroy()
  188. CharacterHumanoid, CharacterTorso = Character:WaitForChild("Humanoid"), Character:WaitForChild("Torso")
  189. CharacterHumanoid.PlatformStand = true
  190. CharacterHumanoid.Changed:connect(function()
  191. CharacterHumanoid.PlatformStand = true
  192. CharacterHumanoid.Jump = false
  193. end)
  194. new("Motor6D", Torso){Part0 = Torso, Part1 = CharacterTorso, C0 = CN(0, 5, 0)}
  195.  
  196. Chatting = false
  197. Moving = false
  198. MaxSpeed = 30
  199. Acceleration = 1
  200. Deceleration = 1
  201. SpeedW = 0
  202. SpeedA = 0
  203. SpeedS = 0
  204. SpeedD = 0
  205. Velocity = V3()
  206. CameraAngleX, CameraAngleY = 45, 45
  207. Dragging = false
  208. Keys = {}
  209.  
  210. UserInputService.InputBegan:connect(function(Input)
  211. local Key, InputType, Delta = Input.KeyCode.Name, Input.UserInputType.Name, Input.Delta
  212. if Key == "Slash" and not Chatting then
  213. Chatting = true
  214. Keys = {}
  215. elseif Key == "Return" and Chatting then
  216. Chatting = false
  217. elseif (Key == "W" or Key == "A" or Key == "S" or Key == "D") and not Chatting then
  218. Keys[Key] = true
  219. end
  220. --[[ if InputType == "MouseButton2" then
  221. Dragging = true
  222. UserInputService.MouseBehavior = "LockCurrentPosition"
  223. end]]
  224. end)
  225.  
  226. --[[UserInputService.InputChanged:connect(function(Input)
  227. local Key, InputType, Delta, Position = Input.KeyCode.Name, Input.UserInputType.Name, Input.Delta, Input.Position
  228. if InputType == "MouseMovement" and Dragging then
  229. CameraAngleX = CameraAngleX+Delta.Y*0.2
  230. if CameraAngleX > 80 then
  231. CameraAngleX = 80
  232. elseif CameraAngleX < -80 then
  233. CameraAngleX = -80
  234. end
  235. CameraAngleY = CameraAngleY-Delta.X*0.2
  236. end
  237. end)]]
  238.  
  239. UserInputService.InputEnded:connect(function(Input)
  240. local Key, InputType, Delta = Input.KeyCode.Name, Input.UserInputType.Name, Input.Delta
  241. if (Key == "W" or Key == "A" or Key == "S" or Key == "D") and not Chatting then
  242. Keys[Key] = nil
  243. end
  244. if InputType == "MouseButton2" then
  245. Dragging = false
  246. UserInputService.MouseBehavior = "Default"
  247. end
  248. end)
  249.  
  250. function UpdateVelocity()
  251. if Keys["W"] then
  252. if SpeedW < MaxSpeed then
  253. SpeedW = SpeedW+Acceleration
  254. else
  255. SpeedW = MaxSpeed
  256. end
  257. else
  258. if SpeedW > 0 then
  259. SpeedW = SpeedW-Deceleration
  260. else
  261. SpeedW = 0
  262. end
  263. end
  264. if Keys["A"] then
  265. if SpeedA < MaxSpeed then
  266. SpeedA = SpeedA+Acceleration
  267. else
  268. SpeedA = MaxSpeed
  269. end
  270. else
  271. if SpeedA > 0 then
  272. SpeedA = SpeedA-Deceleration
  273. else
  274. SpeedA = 0
  275. end
  276. end
  277. if Keys["S"] then
  278. if SpeedS < MaxSpeed then
  279. SpeedS = SpeedS+Acceleration
  280. else
  281. SpeedS = MaxSpeed
  282. end
  283. else
  284. if SpeedS > 0 then
  285. SpeedS = SpeedS-Deceleration
  286. else
  287. SpeedS = 0
  288. end
  289. end
  290. if Keys["D"] then
  291. if SpeedD < MaxSpeed then
  292. SpeedD = SpeedD+Acceleration
  293. else
  294. SpeedD = MaxSpeed
  295. end
  296. else
  297. if SpeedD > 0 then
  298. SpeedD = SpeedD-Deceleration
  299. else
  300. SpeedD = 0
  301. end
  302. end
  303. Velocity = V3(SpeedD-SpeedA, 0, SpeedS-SpeedW)
  304. end
  305.  
  306. Game:GetService("RunService").Stepped:connect(function(Time)
  307. --Animation
  308. if Moving then
  309. for L, Leg in pairs(RightLegs) do
  310. local RightLeg1 = Leg[1]
  311. local RightLeg2 = Leg[2]
  312. local RightLeg3 = Leg[3]
  313.  
  314. local LeftLeg1 = LeftLegs[L][1]
  315. local LeftLeg2 = LeftLegs[L][2]
  316. local LeftLeg3 = LeftLegs[L][3]
  317.  
  318. local Mult = 1-L%2*2
  319.  
  320. --C0 = CN(-1.5, -1.5, -2+L)*CA(0, math.rad(-45+L*15), math.rad(45))*CN(0, 2.5, 0)
  321. --C0 = CN(0, 2.1, 0)*CA(0, 0, math.rad(60))*CN(0, 2.5, 0)
  322. --C0 = CN(0, 2.2, 0)*CA(0, 0, math.rad(60))*CN(0, 2.5, 0)
  323.  
  324. RightLeg1.Motor6D.C0 = Lerp(RightLeg1.Motor6D.C0, CN(1.5, -1.5, -2+L)*CA(0, math.rad(45-L*15+math.sin(Time*20)*Mult*30), math.rad(-45+math.sin(Time*20)*Mult*30))*CN(0, 2.5, 0), 0.1)
  325. LeftLeg1.Motor6D.C0 = Lerp(LeftLeg1.Motor6D.C0, CN(-1.5, -1.5, -2+L)*CA(0, math.rad(-45+L*15+math.sin(Time*20)*Mult*-30), math.rad(45+math.sin(Time*20)*Mult*-30))*CN(0, 2.5, 0), 0.1)
  326. end
  327. else
  328. for L, Leg in pairs(RightLegs) do
  329. local RightLeg1 = Leg[1]
  330. local RightLeg2 = Leg[2]
  331. local RightLeg3 = Leg[3]
  332.  
  333. local LeftLeg1 = LeftLegs[L][1]
  334. local LeftLeg2 = LeftLegs[L][2]
  335. local LeftLeg3 = LeftLegs[L][3]
  336.  
  337. local Mult = 1-L%2*2
  338.  
  339. --C0 = CN(-1.5, -1.5, -2+L)*CA(0, math.rad(-45+L*15), math.rad(45))*CN(0, 2.5, 0)
  340. --C0 = CN(0, 2.1, 0)*CA(0, 0, math.rad(60))*CN(0, 2.5, 0)
  341. --C0 = CN(0, 2.2, 0)*CA(0, 0, math.rad(60))*CN(0, 2.5, 0)
  342.  
  343. RightLeg1.Motor6D.C0 = Lerp(RightLeg1.Motor6D.C0, CN(1.5, -1.5, -2+L)*CA(0, math.rad(45-L*15), math.rad(-45))*CN(0, 2.5, 0), 0.25)
  344. LeftLeg1.Motor6D.C0 = Lerp(LeftLeg1.Motor6D.C0, CN(-1.5, -1.5, -2+L)*CA(0, math.rad(-45+L*15), math.rad(45))*CN(0, 2.5, 0), 0.25)
  345. end
  346. end
  347. end)
  348. Game:GetService("RunService").RenderStepped:connect(function()
  349. UpdateVelocity()
  350. if math.abs(SpiderVelocity.velocity.X) > 0 or math.abs(SpiderVelocity.velocity.Z) > 0 then
  351. Moving = true
  352. else
  353. Moving = false
  354. end
  355. local CoordinateFrame2D = CN(V3(Camera.CoordinateFrame.X, Platform.CFrame.Y, Camera.CoordinateFrame.Z), Platform.Position)
  356. local RelativeVelocity = CoordinateFrame2D*Velocity-CoordinateFrame2D.p
  357. SpiderVelocity.velocity = RelativeVelocity
  358. SpiderGyro.cframe = CN(CoordinateFrame2D.p, Platform.Position)
  359.  
  360. --Camera:Interpolate(CN(Torso.Position)*CA(0, math.rad(CameraAngleY), 0)*CA(math.rad(CameraAngleX), 0, 0)*CN(0, 0, -20), Torso.CFrame, 0.01)
  361. end)
Add Comment
Please, Sign In to add comment