LeGoldenRobloxian

through Apples

Jun 1st, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.91 KB | None | 0 0
  1. do --CFrame lerp (stravant, clerp by AntiBoomz0r)
  2. local function QuaternionFromCFrame(cf)
  3. local mx, my, mz, m00, m01, m02, m10, m11, m12, m20, m21, m22 = cf:components()
  4. local trace = m00 + m11 + m22
  5. if trace > 0 then
  6. local s = math.sqrt(1 + trace)
  7. local recip = 0.5/s
  8. return (m21-m12)*recip, (m02-m20)*recip, (m10-m01)*recip, s*0.5
  9. else
  10. local i = 0
  11. if m11 > m00 then
  12. i = 1
  13. end
  14. if m22 > (i == 0 and m00 or m11) then
  15. i = 2
  16. end
  17. if i == 0 then
  18. local s = math.sqrt(m00-m11-m22+1)
  19. local recip = 0.5/s
  20. return 0.5*s, (m10+m01)*recip, (m20+m02)*recip, (m21-m12)*recip
  21. elseif i == 1 then
  22. local s = math.sqrt(m11-m22-m00+1)
  23. local recip = 0.5/s
  24. return (m01+m10)*recip, 0.5*s, (m21+m12)*recip, (m02-m20)*recip
  25. elseif i == 2 then
  26. local s = math.sqrt(m22-m00-m11+1)
  27. local recip = 0.5/s return (m02+m20)*recip, (m12+m21)*recip, 0.5*s, (m10-m01)*recip
  28. end
  29. end
  30. end
  31. local function QuaternionToCFrame(px, py, pz, x, y, z, w)
  32. local xs, ys, zs = x + x, y + y, z + z
  33. local wx, wy, wz = w*xs, w*ys, w*zs
  34. local xx = x*xs
  35. local xy = x*ys
  36. local xz = x*zs
  37. local yy = y*ys
  38. local yz = y*zs
  39. local zz = z*zs
  40. 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))
  41. end
  42. local function QuaternionSlerp(a, b, t)
  43. local cosTheta = a[1]*b[1] + a[2]*b[2] + a[3]*b[3] + a[4]*b[4]
  44. local startInterp, finishInterp;
  45. if cosTheta >= 0.0001 then
  46. if (1 - cosTheta) > 0.0001 then
  47. local theta = math.acos(cosTheta)
  48. local invSinTheta = 1/math.sin(theta)
  49. startInterp = math.sin((1-t)*theta)*invSinTheta
  50. finishInterp = math.sin(t*theta)*invSinTheta
  51. else
  52. startInterp = 1-t
  53. finishInterp = t
  54. end
  55. else
  56. if (1+cosTheta) > 0.0001 then
  57. local theta = math.acos(-cosTheta)
  58. local invSinTheta = 1/math.sin(theta)
  59. startInterp = math.sin((t-1)*theta)*invSinTheta
  60. finishInterp = math.sin(t*theta)*invSinTheta
  61. else
  62. startInterp = t-1
  63. finishInterp = t
  64. end
  65. end
  66. 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
  67. end
  68. function clerp(a,b,t)
  69. local qa = {QuaternionFromCFrame(a)}
  70. local qb = {QuaternionFromCFrame(b)}
  71. local ax, ay, az = a.x, a.y, a.z
  72. local bx, by, bz = b.x, b.y, b.z
  73. local _t = 1-t
  74. return QuaternionToCFrame(_t*ax + t*bx, _t*ay + t*by, _t*az + t*bz,QuaternionSlerp(qa, qb, t))
  75. end
  76. end
  77.  
  78.  
  79. do --rayCast
  80. function rayCast(startpos, Speed, Gravity, Dmg)
  81. local ran,err = ypcall(function()
  82. local rayPart = Instance.new("Part", char)
  83. rayPart.Name = "RayPart"
  84. rayPart.BrickColor = BrickColor.new("Really red")
  85. rayPart.Anchored = true
  86. rayPart.Shape = Shape or "Ball"
  87. rayPart.CanCollide = false
  88. rayPart.Locked = true
  89. rayPart.TopSurface = Enum.SurfaceType.Smooth
  90. rayPart.BottomSurface = Enum.SurfaceType.Smooth
  91. rayPart.Size = Vector3.new(.2, 2, .2)
  92. local msh = Instance.new("SpecialMesh",rayPart)
  93. msh.MeshId = "http://www.roblox.com/asset/?id=16190555"
  94. msh.TextureId = "http://www.roblox.com/asset/?id=16190577"
  95. msh.Scale = Vector3.new(2, 2, 2)
  96.  
  97.  
  98.  
  99.  
  100. local bulletposition = startpos.Position
  101. rayPart.CFrame = startpos.CFrame
  102.  
  103. local bulletvelocity = (Vector3.new(math.random(-2,2), math.random(-2,2), math.random(-2,2)))+( mouse.Hit.p - bulletposition).unit*Speed
  104. local bulletlastposition = bulletposition
  105.  
  106.  
  107.  
  108. coroutine.resume(coroutine.create(function()
  109. while true do
  110. local dt = wait()
  111. bulletlastposition = bulletposition
  112. bulletvelocity = bulletvelocity + (Vector3.new(0, -3.81*Gravity, 0)*dt)
  113. bulletposition = bulletposition + (bulletvelocity*dt)
  114.  
  115. local ray = Ray.new(bulletlastposition, (bulletposition - bulletlastposition))
  116.  
  117. local hit, hitposition = workspace:FindPartOnRayWithIgnoreList( ray, { char, rayPart, camera} )
  118.  
  119. if (torso.Position - rayPart.Position).magnitude > 540 then
  120. rayPart:Destroy()
  121. break
  122. end
  123.  
  124.  
  125. if hit then
  126. local damage = math.random(Dmg, Dmg+6)
  127. if hit.Parent:findFirstChild("Humanoid") ~= nil then
  128. hit.Parent.Humanoid.Health = hit.Parent.Humanoid.Health - damage
  129. elseif hit.Parent:IsA("Hat") and hit.Parent.Parent:findFirstChild("Humanoid") then
  130. hit.Parent.Parent.Humanoid.Health = hit.Parent.Parent.Humanoid.Health - damage
  131. end
  132. bulletposition = hitposition
  133. rayPart.CFrame = CFrame.new(bulletposition, bulletposition+bulletvelocity) * CFrame.Angles(math.pi/2, 0, 0)
  134. for i = 1, 50 do
  135. local s = Instance.new("Part")
  136. s.CanCollide = false
  137. s.Shape = 1
  138. s.Locked = true
  139. s.formFactor = "Custom"
  140. pl = Instance.new("PointLight", s)
  141. pl.Range = 8
  142. pl.Color = Color3.new(0.8, 0.8, 0)
  143. s.Size = Vector3.new(.3,.3,.3)
  144. s.Transparency = 0.5
  145. s.BrickColor = BrickColor.new("Brick yellow")
  146. local v = Vector3.new(math.random(-1,1), math.random(1,2), math.random(-1,1))
  147. s.Velocity = 0.5 * v
  148. s.CFrame = CFrame.new(rayPart.Position + v, v)
  149. s.Parent = workspace
  150. coroutine.resume(coroutine.create(function()
  151. wait(2)
  152. s:Destroy()
  153. end))
  154. end
  155. rayPart:Destroy()
  156. break
  157. end
  158. rayPart.CFrame = CFrame.new(bulletposition, bulletposition+bulletvelocity) * CFrame.Angles(math.pi/2, 0, 0)
  159. rayPart.Parent = workspace
  160. end
  161. end))
  162. end)
  163. if not ran and err then
  164. print(err)
  165. end
  166. end
  167. end
  168.  
  169. do --the animating
  170. plr = game:service'Players'.LocalPlayer
  171. char = plr.Character
  172. mouse = plr:GetMouse()
  173. humanoid = char:findFirstChild("Humanoid")
  174. torso = char:findFirstChild("Torso")
  175. head = char.Head
  176. ra = char:findFirstChild("Right Arm")
  177. la = char:findFirstChild("Left Arm")
  178. rl = char:findFirstChild("Right Leg")
  179. ll = char:findFirstChild("Left Leg")
  180. rs = torso:findFirstChild("Right Shoulder")
  181. ls = torso:findFirstChild("Left Shoulder")
  182. rh = torso:findFirstChild("Right Hip")
  183. lh = torso:findFirstChild("Left Hip")
  184. neck = torso:findFirstChild("Neck")
  185. rj = char:findFirstChild("HumanoidRootPart"):findFirstChild("RootJoint")
  186. anim = char:findFirstChild("Animate")
  187. rootpart = char:findFirstChild("HumanoidRootPart")
  188. camera = workspace.CurrentCamera
  189.  
  190.  
  191. local rm = Instance.new("Weld", torso)
  192. rm.C0 = CFrame.new(1.5, 0.5, 0)
  193. rm.C1 = CFrame.new(0, 0.5, 0)
  194. rm.Part0 = torso
  195. rm.Part1 = ra
  196. local lm = Instance.new("Weld", torso)
  197. lm.C0 = CFrame.new(-1.5, 0.5, 0)
  198. lm.C1 = CFrame.new(0, 0.5, 0)
  199. lm.Part0 = torso
  200. lm.Part1 = la
  201.  
  202.  
  203.  
  204. local speed = 0.3
  205. local angle = 0
  206. local anglespeed = 1
  207. rsc0 = rm.C0
  208. lsc0 = lm.C0
  209. rjc0 = rj.C0
  210. neckc0 = neck.C0
  211. radian = math.rad
  212.  
  213. apple = Instance.new("Part", char)
  214. apple.FormFactor = "Custom"
  215. apple.Size = Vector3.new(1, 1, 1)
  216. apple:breakJoints()
  217. local wld = Instance.new("Weld", char)
  218. wld.C1 = CFrame.new(0, -1, 0)
  219. wld.C0 = CFrame.Angles(math.pi, 0, 0)
  220. wld.Part1 = ra
  221. wld.Part0 = apple
  222. local msh = Instance.new("SpecialMesh", apple)
  223. msh.MeshId = "http://www.roblox.com/asset/?id=16190555"
  224. msh.TextureId = "http://www.roblox.com/asset/?id=16190577"
  225. msh.Scale = Vector3.new(2, 2, 2)
  226.  
  227.  
  228.  
  229. mouse.Button1Down:connect(function()
  230. if throwing then return end
  231. throwing = true
  232. wait(wait()*8)
  233. for trans = 1, 0, -0.1 do
  234. apple.Transparency = trans
  235. wait()
  236. end
  237. end)
  238.  
  239. done = false
  240. while wait() do
  241. angle = (angle % 100) + anglespeed/10
  242. mvmnt = math.pi * math.sin(math.pi*2/100*(angle*10))
  243. local rscf = rsc0
  244. local lscf = lsc0
  245. local rjcf = rjc0
  246. local ncf = neckc0
  247. lscf = lsc0 * CFrame.Angles(-radian(5), 0, -radian(5))
  248. if throwing then
  249. for waiting = 0, 250, 30 do
  250. if done then return end
  251. rscf = rsc0 * CFrame.Angles(radian(waiting), 0, 0)
  252. rm.C0 = clerp(rm.C0,rscf,speed)
  253. wait()
  254. if waiting == 250 then
  255. done = true
  256. end
  257. end
  258. rscf = rsc0 * CFrame.Angles(radian(120), 0, 0)
  259. rayCast(apple, math.random(140, 150), 20, 28)
  260. throwing = false
  261. done = false
  262. end
  263. rm.C0 = clerp(rm.C0,rscf,speed)
  264. lm.C0 = clerp(lm.C0,lscf,speed)
  265. rj.C0 = clerp(rj.C0,rjcf,speed)
  266. neck.C0 = clerp(neck.C0,ncf,speed)
  267. end
  268. end
Add Comment
Please, Sign In to add comment