null nil 0 Sticky Poop rbxasset://textures//PaintballIcon.png true false -0.5 0.5 0 0 -0.5 0.5 0 0 141 0 7.30000067 -8 1 0 0 0 1 0 0 0 1 true true 0 true true false 0.5 0 0.300000012 -0.5 0.5 0 0 -0.5 0.5 0 0 false Pellet 0 -0.5 0.5 0 0 0 0 0 -0.5 0.5 0 0 0 0 0 0 true 0 1 1 1 true PelletScript pellet = script.Parent damage = 8 function stick(hit) -- joint myself to the thing i hit local weld = Instance.new("Weld") weld.Part0 = pellet weld.Part1 = hit local HitPos = pellet.Position + (pellet.CFrame.lookVector * .5) local CJ = CFrame.new(HitPos) local C0 = pellet.CFrame:inverse() *CJ local C1 = hit.CFrame:inverse() * CJ weld.C0 = C0 weld.C1 = C1 weld.Parent = pellet end function onTouched(hit) stick(hit) humanoid = hit.Parent:findFirstChild("Humanoid") wait(2) local boom = Instance.new("Explosion") boom.Position = script.Parent.Position boom.Parent = game.Workspace boom.BlastRadius = 8 sound = Instance.new("Sound") sound.SoundId = "rbxasset://sounds\\Rocket shot.wav" sound.Parent = script.Parent sound:play() if humanoid~=nil then tagHumanoid(humanoid) humanoid.Health = humanoid.Health - damage wait(1.87345) untagHumanoid(humanoid) else damage = damage / 2 if damage < 0.1 then connection:disconnect() end end end function tagHumanoid(humanoid) -- todo: make tag expire local tag = pellet:findFirstChild("creator") if tag ~= nil then local new_tag = tag:clone() new_tag.Parent = humanoid end end function untagHumanoid(humanoid) if humanoid ~= nil then local tag = humanoid:findFirstChild("creator") if tag ~= nil then tag.Parent = nil end end end connection = pellet.Touched:connect(onTouched) r = game:service("RunService") t, s = r.Stepped:wait() d = t + 2.0 - s while t < d do t = r.Stepped:wait() end wait(0.5) pellet.Parent = nil true false Slingshot print("Slingshot script loaded") bin = script.Parent VELOCITY = 150 -- constant function fire(mouse_pos) sound = Instance.new("Sound") sound.SoundId = "rbxasset://sounds\\splat.wav" sound.Parent = script.Parent sound:play() -- find player's head pos local head = game.Players.LocalPlayer.Character:findFirstChild("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 -- acceleration due to gravity in RBX units 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 = script.Parent.Pellet:clone() missile.Position = launch missile.Velocity = Vector3.new(vx,vy,vz) * VELOCITY print("Pos X:", launch.x, "Y:", launch.y, "Z:", launch.z) print("Vel X:", vx, "Y:", vy, "Z:", vz) missile.PelletScript.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 end function computeLaunchAngle(dx,dy,grav) -- arcane -- http://en.wikipedia.org/wiki/Trajectory_of_a_projectile local g = math.abs(grav) local inRoot = (VELOCITY*VELOCITY*VELOCITY*VELOCITY) - (g * ((g*dx*dx) + (2*dy*VELOCITY*VELOCITY))) if inRoot <= 0 then return .25 * math.pi end local root = math.sqrt(inRoot) local inATan1 = ((VELOCITY*VELOCITY) + root) / (g*dx) local inATan2 = ((VELOCITY*VELOCITY) - 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 enabled = true function onButton1Down(mouse) if not enabled then return end enabled = false mouse.Icon = "rbxasset://textures\\GunWaitCursor.png" -- find the best cf --local cf = mouse.Hit --local v = cf.lookVector local pos = mouse.Hit.p fire(pos) wait(4) mouse.Icon = "rbxasset://textures\\GunCursor.png" enabled = true end function onSelected(mouse) print("slingshot selected") mouse.Icon = "rbxasset://textures\\GunCursor.png" mouse.Button1Down:connect(function() onButton1Down(mouse) end) end bin.Selected:connect(onSelected) true false Sound 1 false rbxasset://sounds\splat.wav 0.5 true false Sound 1 false rbxasset://sounds\splat.wav 0.5 true