Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- To be used with the quickscripts plugin https://www.roblox.com/library/5602756723/QuickScript
- local BulletSpeed = 300 -- Feet per second, 300 is around the speed of a paintball, 900 is around the speed of a handgun
- local SimulationSpeed = 1 -- How fast time moves, Example; SimulationSpeed = 1/10 would make time flow 10 times slower
- local Gravity = 20 -- How much to accellerate bullets downwards, 1 gravity means Velocity.Y increases by -1 every second
- local TestKey
- local Bullets = {}
- local SpawnBullet = function(Origin, Direction, Speed)
- local BulletData = {
- Position = Origin;
- Velocity = Direction.Unit * Speed;
- LastPosition = nil;
- }
- local raycastParams = RaycastParams.new()
- raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
- raycastParams.FilterDescendantsInstances = {workspace.Bullets, workspace.Hits}
- BulletData.raycastParams = raycastParams
- local BulletPart = Instance.new("Part", workspace.Bullets)
- BulletPart.Name = "BulletPart"
- BulletPart.Size = Vector3.new(.45,.45,.45)
- BulletPart.Color = Color3.new(1,1,0)
- BulletPart.Anchored = true
- BulletData.Part = BulletPart
- Bullets[BulletData] = true
- return BulletData
- end
- local DeleteBullet = function(BulletData)
- repeat
- BulletData.Part:Destroy()
- until BulletData.Part.Parent == nil or _G.TestKey ~= TestKey
- Bullets[BulletData] = nil
- end
- local UpdateBullet = function(BulletData, Delta)
- BulletData.Velocity = BulletData.Velocity - Vector3.new(0,Gravity,0)*Delta
- BulletData.LastPosition = BulletData.Position
- BulletData.Position = BulletData.Position + BulletData.Velocity * (Delta or 1)
- local Difference = BulletData.Position - BulletData.LastPosition
- local Distance = Difference.magnitude
- BulletData.Part.Size = Vector3.new(0.2, 0.2, math.max(Distance,0.2))
- BulletData.Part.CFrame = CFrame.new(BulletData.Position, BulletData.LastPosition)
- *CFrame.new(0,0,-BulletData.Part.Size.Z/2)
- local rayOrigin = BulletData.LastPosition
- local rayDirection = BulletData.Position - BulletData.LastPosition
- local raycastResult = workspace:Raycast(rayOrigin, rayDirection, BulletData.raycastParams)
- if raycastResult then
- local Marker = Instance.new("Part")
- Marker.Size = Vector3.new(.4,.4,.2)
- Marker.CFrame = CFrame.new(raycastResult.Position, raycastResult.Position + raycastResult.Normal)
- Marker.Color = Color3.new(0.1,0.1,0.1)
- Marker.Parent = workspace.Hits
- DeleteBullet(BulletData)
- elseif BulletData.Position.Y < -100 then
- DeleteBullet(BulletData)
- end
- return raycastResult
- end
- return function(QuickScripts)
- repeat
- TestKey = math.random(1,1000000)
- until TestKey ~= _G.TestKey
- _G.TestKey = TestKey
- if not workspace:FindFirstChild("Bullets") then
- Instance.new("Model",workspace).Name = "Bullets"
- end
- if not workspace:FindFirstChild("Hits") then
- Instance.new("Model",workspace).Name = "Hits"
- end
- workspace.Bullets:ClearAllChildren()
- workspace.Hits:ClearAllChildren()
- local plugin = QuickScripts.plugin
- plugin:Activate(true)
- local Mouse = plugin:GetMouse()
- local BulletShooter = Mouse.Button1Down:connect(function(k)
- local Camera = workspace.CurrentCamera
- SpawnBullet(Camera.CFrame.p-Vector3.new(0,1,0), Camera.CFrame.LookVector, BulletSpeed)
- end)
- local BulletUpdater;BulletUpdater = game:GetService("RunService").RenderStepped:connect(function(Delta)
- if _G.TestKey ~= TestKey then
- BulletUpdater:disconnect()
- BulletShooter:disconnect()
- return
- end
- for BulletData in pairs(Bullets) do
- UpdateBullet(BulletData, Delta * SimulationSpeed)
- end
- end)
- end
Add Comment
Please, Sign In to add comment