Vzurxy

Untitled

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