Advertisement
Guest User

Untitled

a guest
Nov 24th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. sqrt = math.sqrt
  2. tan = math.tan
  3. cos = math.cos
  4. atan = math.atan
  5.  
  6. function CalculateThrow(mode,start,finish,...)
  7. local variables = {...}
  8.  
  9. if mode == "bullet" then
  10. local g = workspace.Gravity
  11.  
  12. local distance = (start-finish).magnitude
  13.  
  14. if distance > 150 then distance = 150 end
  15.  
  16. local angle = math.rad(15) * distance/150
  17.  
  18. local direction = ((finish-start)*Vector3.new(1,0,1)).unit
  19.  
  20. local x = (start * Vector3.new(1,0,1)-finish * Vector3.new(1,0,1)).magnitude -- target x
  21. local o = angle -- launch angle
  22. local v = (sqrt(g) * sqrt(x) * sqrt((tan(o)*tan(o))+1)) / sqrt(2 * tan(o)) -- velocity
  23. local t = -(math.sin(angle) * v) / g
  24.  
  25. if variables[1] then
  26.  
  27. local lead = t * variables[1] * 2
  28.  
  29. return CalculateThrow(mode, start, finish - lead)
  30.  
  31. end
  32.  
  33. return v, direction, angle, t
  34.  
  35. elseif mode=="lob" then
  36. local g = workspace.Gravity
  37. local distance = (start-finish).magnitude
  38. if distance > 50 then distance = 50 end
  39.  
  40. local angle = math.rad(50) * distance/50
  41. local direction = ((finish-start)*Vector3.new(1,0,1)).unit
  42. local x = (start * Vector3.new(1,0,1)-finish * Vector3.new(1,0,1)).magnitude -- target x
  43. local o = angle -- launch angle
  44. local v = (sqrt(g) * sqrt(x) * sqrt((tan(o)*tan(o))+1)) / sqrt(2 * tan(o)) -- velocity
  45. local t = -(math.sin(angle) * v) / g
  46.  
  47. if variables[1] then
  48. local lead = t * variables[1] * 2
  49. return CalculateThrow(mode, start, finish - lead)
  50. end
  51.  
  52. return v, direction, angle, t
  53.  
  54. end
  55.  
  56. end
  57.  
  58. function Draw(start,finish,lifetime)
  59. local P = Instance.new("Part");
  60. local M = Instance.new("CylinderMesh",P); -- ya
  61. local Distance = (start-finish).magnitude
  62.  
  63. P.Anchored = true;
  64. P.CanCollide = false;
  65.  
  66.  
  67. P.Size = Vector3.new(0.45,Distance,0.45) -- ya but its too big, its just creates parts on top of eachother
  68. P.CFrame = CFrame.new(start,finish) * CFrame.Angles(math.pi/2,0,0) * CFrame.new(0,-Distance/2,0)
  69.  
  70. P.Parent = workspace; --???
  71. game:GetService("Debris"):AddItem(P,lifetime);
  72. end;
  73.  
  74. function Preview(frame,velocity,time_,start,finish) -- good point
  75. local distance = (start-finish).magnitude;
  76. local previous = frame.p;
  77. local _time = time_/distance/5;
  78.  
  79.  
  80. for i = 1,distance/5 do
  81. local new = previous-velocity*_time-Vector3.new(0,2*_time,0); --[[Y = workspace.Gravity]]
  82.  
  83. Draw(previous,new,1);
  84. previous = new; -- shh not my fault
  85. end;
  86.  
  87. end;
  88.  
  89. wait(4)
  90. while wait() do
  91.  
  92. workspace.a.CFrame = CFrame.new(-36.8,workspace.expounding.Torso.Position.Y,-17)
  93. dude = workspace.c:Clone()
  94. dude.Parent = workspace
  95. local velocity, direction, angle, t = CalculateThrow("bullet", workspace.a.Position, workspace.expounding.Torso.Position, workspace.expounding.Torso.Velocity)
  96. local frame = CFrame.new(workspace.a.Position, workspace.a.Position + direction) * CFrame.Angles(angle,0,0)
  97.  
  98. Preview(frame,frame.lookVector*velocity,t,workspace.a.Position,workspace.expounding.Torso.Position)
  99. --Draw(Vector3.new(0,5,0),Vector3.new(10,5,0),1)
  100. dude.CFrame = frame
  101. dude.Velocity = frame.lookVector * velocity
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement