VELOCITY=90 function firenade(y)nadeloaded=false local Z=(game.Workspace:findFirstChild(script.Parent.Parent.Name)).Head if Z==nil then return end local s=y-Z.Position s=computeDirection(s)local A=Z.Position+5*s local M=y-A local h=M.y local t=Vector3.new(M.x,0,M.z)M=t local Q=M.magnitude local L=M.unit local N=-196.2 local V=computeLaunchAngle(Q,h,N)local b=math.sin(V)local a=math.cos(V)local x=L.x*a local E=L.z*a local l=Instance.new("\080\097\114\116")l.Size=Vector3.new(1,1,1)l.BrickColor=BrickColor.new(0)l.Shape=0 l.BottomSurface=0 l.TopSurface=0 l.Name="\071\114\101\110\097\100\101"l.Elasticity=.2 l.Reflectance=0 l.Friction=.8 l.Position=A l.Velocity=Vector3.new(x,b,E)*VELOCITY;(script.Parent.GrenadeScript:clone()).Parent=l l.GrenadeScript.Disabled=false local q=Instance.new("\079\098\106\101\099\116\086\097\108\117\101")q.Value=game.Players.LocalPlayer q.Name="\099\114\101\097\116\111\114"q.Parent=l l.Parent=game.Workspace wait(.5)script.Parent.mode.Value=script.Parent.mode.Value-10 wait(10)nadeloaded=true end function computeLaunchAngle(y,Z,s)local A=math.abs(s)local M=VELOCITY^4-A*((A*y)*y+(2*Z)*VELOCITY^2)if M<=0 then return.25*math.pi end local h=math.sqrt(M)local t=(VELOCITY^2+h)/(A*y)local Q=(VELOCITY^2-h)/(A*y)local L=math.atan(t)local N=math.atan(Q)if L<N then return L end return N end function computeDirection(y)local Z=y.magnitude*y.magnitude local s=1/math.sqrt(Z)return Vector3.new(y.x*s,y.y*s,y.z*s)end
--------------------------------------------------------------------------------------------------------------------------
----------------------------------------------GRENADES---------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------

VELOCITY = 90

function firenade(mouse_pos)
	nadeloaded = false
	local head = game.Workspace:findFirstChild(script.Parent.Parent.Name).Head
	if head == nil then
		return
	end

	local dir = mouse_pos - head.Position
	dir = computeDirection(dir)

	local launch = head.Position + 5 * dir

	local delta = mouse_pos - launch

	local dy = delta.y

	local new_delta = Vector3.new(delta.x, 0, delta.z)
	delta = new_delta

	local dx = delta.magnitude
	local unit_delta = delta.unit

	local g = (-9.81 * 20)

	local theta = computeLaunchAngle(dx, dy, g)

	local vy = math.sin(theta)
	local xz = math.cos(theta)
	local vx = unit_delta.x * xz
	local vz = unit_delta.z * xz

	local missile = Instance.new("Part")
	missile.Size = Vector3.new(1, 1, 1)
	missile.BrickColor = BrickColor.new(0)
	missile.Shape = 0
	missile.BottomSurface = 0
	missile.TopSurface = 0
	missile.Name = "Grenade"
	missile.Elasticity = 0.2
	missile.Reflectance = 0
	missile.Friction = 0.8
	missile.Position = launch
	missile.Velocity = Vector3.new(vx, vy, vz) * VELOCITY

	script.Parent.GrenadeScript:clone().Parent = missile
	missile.GrenadeScript.Disabled = false

	local creator_tag = Instance.new("ObjectValue")
	creator_tag.Value = game.Players.LocalPlayer
	creator_tag.Name = "creator"
	creator_tag.Parent = missile

	missile.Parent = game.Workspace

	wait(0.5)
	script.Parent.mode.Value = script.Parent.mode.Value - 10
	wait(10)
	nadeloaded = true
end

function computeLaunchAngle(dx, dy, grav)
	local g = math.abs(grav)
	local inRoot = (VELOCITY ^ 4) - (g * ((g * dx * dx) + (2 * dy * (VELOCITY ^ 2))))
	if inRoot <= 0 then
		return 0.25 * math.pi
	end
	local root = math.sqrt(inRoot)
	local inATan1 = ((VELOCITY ^ 2) + root) / (g * dx)

	local inATan2 = ((VELOCITY ^ 2) - root) / (g * dx)
	local answer1 = math.atan(inATan1)
	local answer2 = math.atan(inATan2)
	if answer1 < answer2 then
		return answer1
	end
	return answer2
end

function computeDirection(vec)
	local lenSquared = vec.magnitude * vec.magnitude
	local invSqrt = 1 / math.sqrt(lenSquared)
	return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end
