Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sqrt = math.sqrt
- tan = math.tan
- cos = math.cos
- atan = math.atan
- function CalculateThrow(mode,start,finish,...)
- local variables = {...}
- if mode == "bullet" then
- local g = workspace.Gravity
- local distance = (start-finish).magnitude
- if distance > 150 then distance = 150 end
- local angle = math.rad(15) * distance/150
- local direction = ((finish-start)*Vector3.new(1,0,1)).unit
- local x = (start * Vector3.new(1,0,1)-finish * Vector3.new(1,0,1)).magnitude -- target x
- local o = angle -- launch angle
- local v = (sqrt(g) * sqrt(x) * sqrt((tan(o)*tan(o))+1)) / sqrt(2 * tan(o)) -- velocity
- local t = -(math.sin(angle) * v) / g
- if variables[1] then
- local lead = t * variables[1] * 2
- return CalculateThrow(mode, start, finish - lead)
- end
- return v, direction, angle, t
- elseif mode=="lob" then
- local g = workspace.Gravity
- local distance = (start-finish).magnitude
- if distance > 50 then distance = 50 end
- local angle = math.rad(50) * distance/50
- local direction = ((finish-start)*Vector3.new(1,0,1)).unit
- local x = (start * Vector3.new(1,0,1)-finish * Vector3.new(1,0,1)).magnitude -- target x
- local o = angle -- launch angle
- local v = (sqrt(g) * sqrt(x) * sqrt((tan(o)*tan(o))+1)) / sqrt(2 * tan(o)) -- velocity
- local t = -(math.sin(angle) * v) / g
- if variables[1] then
- local lead = t * variables[1] * 2
- return CalculateThrow(mode, start, finish - lead)
- end
- return v, direction, angle, t
- end
- end
- function Draw(start,finish,lifetime)
- local P = Instance.new("Part");
- local M = Instance.new("CylinderMesh",P); -- ya
- local Distance = (start-finish).magnitude
- P.Anchored = true;
- P.CanCollide = false;
- P.Size = Vector3.new(0.45,Distance,0.45) -- ya but its too big, its just creates parts on top of eachother
- P.CFrame = CFrame.new(start,finish) * CFrame.Angles(math.pi/2,0,0) * CFrame.new(0,-Distance/2,0)
- P.Parent = workspace; --???
- game:GetService("Debris"):AddItem(P,lifetime);
- end;
- function Preview(frame,velocity,time_,start,finish) -- good point
- local distance = (start-finish).magnitude;
- local previous = frame.p;
- local _time = time_/distance/5;
- for i = 1,distance/5 do
- local new = previous-velocity*_time-Vector3.new(0,2*_time,0); --[[Y = workspace.Gravity]]
- Draw(previous,new,1);
- previous = new; -- shh not my fault
- end;
- end;
- wait(4)
- while wait() do
- workspace.a.CFrame = CFrame.new(-36.8,workspace.expounding.Torso.Position.Y,-17)
- dude = workspace.c:Clone()
- dude.Parent = workspace
- local velocity, direction, angle, t = CalculateThrow("bullet", workspace.a.Position, workspace.expounding.Torso.Position, workspace.expounding.Torso.Velocity)
- local frame = CFrame.new(workspace.a.Position, workspace.a.Position + direction) * CFrame.Angles(angle,0,0)
- Preview(frame,frame.lookVector*velocity,t,workspace.a.Position,workspace.expounding.Torso.Position)
- --Draw(Vector3.new(0,5,0),Vector3.new(10,5,0),1)
- dude.CFrame = frame
- dude.Velocity = frame.lookVector * velocity
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement