while wait() do
if game:IsLoaded()==true then
break
end
end
local Tool=script.Parent
local Player=game.Players.LocalPlayer
local Mouse=Player:GetMouse()
local c=Player.Character
local currentIcon="rbxasset://textures\\GunCursor.png"
function Test(var,bool1,bool2)
if var==bool1 then
currentIcon="rbxasset://textures\\GunCursor.png"
elseif var==bool2 then
currentIcon="rbxasset://textures\\GunWaitCursor.png"
end
end
Tool:GetPropertyChangedSignal("Enabled"):connect(function()
Test(Tool.Enabled,true,false)
c=Player.Character
if not c then return end
local t=c:FindFirstChildWhichIsA("Tool")
if not t then return end
if t~=Tool then return end
Mouse.Icon=currentIcon
end)
Tool.Activated:connect(function()
Tool.Fire:FireServer(Mouse.Hit.p)
end)
if not c then
c=Player.CharacterAdded:Wait()
end
local head
local humanoid
while wait() do
head=c:FindFirstChild("Head")
humanoid=c:FindFirstChildWhichIsA("Humanoid")
if head and humanoid then
break
end
end
local iNew=Instance.new
local cf=CFrame.new
local v3=Vector3.new
local terrain=workspace.Terrain
local grav=workspace.Gravity
local cam=workspace.CurrentCamera
local r=game:GetService("RunService")
local attach0=iNew("Attachment")
attach0.Parent=terrain
local attach1=iNew("Attachment")
attach1.Parent=terrain
local beam=iNew("Beam")
beam.Parent=terrain
beam.Attachment0=attach0
beam.Attachment1=attach1
beam.Width0=2
beam.Width1=2
beam.Segments=50
beam.TextureSpeed=0.25
beam.LightEmission=0.25
beam.Texture="rbxassetid://2724621315"
beam.Transparency=NumberSequence.new(0.5)
beam.Color=ColorSequence.new(Color3.new(1,1,1))
--beam.FaceCamera=true
local t=1
local function beamProjectile(g, v0, x0, t1) -- all credit to EgoMoose
-- calculate the bezier points
local c = 0.5*0.5*0.5
local p3 = 0.5*g*t1*t1 + v0*t1 + x0
local p2 = p3 - (g*t1*t1 + v0*t1)/3
local p1 = (c*g*t1*t1 + 0.5*v0*t1 + x0 - c*(x0+p3))/(3*c) - p2;
-- the curve sizes
local curve0 = (p1 - x0).magnitude;
local curve1 = (p2 - p3).magnitude;
-- build the world CFrames for the attachments
local b = (x0 - p3).unit;
local r1 = (p1 - x0).unit;
local u1 = r1:Cross(b).unit;
local r2 = (p2 - p3).unit;
local u2 = r2:Cross(b).unit;
b = u1:Cross(r1).unit;
local cf1=cf(
x0.x, x0.y, x0.z,
r1.x, u1.x, b.x,
r1.y, u1.y, b.y,
r1.z, u1.z, b.z
)
local cf2=cf(
p3.x, p3.y, p3.z,
r2.x, u2.x, b.x,
r2.y, u2.y, b.y,
r2.z, u2.z, b.z
)
return curve0, -curve1, cf1, cf2;
end
local function getTrajectory()
if not c then return end
local tool=c:FindFirstChildWhichIsA("Tool")
if (not tool) or tool.Parent~=c then return end -- ensure the player is
holding the tool
if attach0.Parent==nil or attach1.Parent==nil or beam.Parent==nil then return
end -- check if theyve been destroyed
if _G.ShowTrajectory==true then
beam.Enabled=true
else
beam.Enabled=false
return
end -- I know this is all very taxing, but otherwise I couldn't get it ALWAYS
working at the correct time
local targetPos=Mouse.Hit.p
local lookAt=(targetPos - head.Position).unit
local spawnPos=head.Position
spawnPos=spawnPos+(lookAt*5)
local g = v3(0, -grav, 0)
local x0 = spawnPos --* v3(0, 2, -2)
--local v0 = (Mouse.Hit.p - x0 - 0.5*g*t*t)/t
local v0 = --[[(]](lookAt*200) -- - 0.5*g*t*t)/t
local curve0, curve1, cf1, cf2 = beamProjectile(g, v0, x0, t)
beam.CurveSize0 = curve0
beam.CurveSize1 = curve1
-- convert world space CFrames to be relative to the attachment parent
attach0.CFrame = (attach0.Parent.CFrame:inverse() * cf1)-v3(0,0.4,0)
attach1.CFrame = (attach1.Parent.CFrame:inverse() * cf2)-v3(0,0.4,0)
end
Tool.Equipped:connect(function()
Mouse.Icon=currentIcon
r:BindToRenderStep("Trajectory",300,getTrajectory)
end)
Tool.Unequipped:connect(function()
Mouse.Icon=""
pcall(function() r:UnbindFromRenderStep("Trajectory") end)
for i,v in pairs(workspace.Terrain:GetChildren()) do
if v:IsA("Beam") then
v.Enabled=false
end
end
end)
humanoid.Died:Connect(function()
for i,v in pairs(workspace.Terrain:GetChildren()) do
if v:IsA("Beam") or v:IsA("Attachment") then
v:Destroy()
end
end
end)