Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- game:GetObjects("rbxassetid://881234702")[1].Parent=game.workspace
- wait(0.3)
- function Shoot()
- while true do
- local laser = Instance.new("Part")
- laser.Name = "Laser"
- laser.FormFactor = Enum.FormFactor.Custom
- laser.TopSurface, laser.BottomSurface = 0, 0
- laser.Size = Vector3.new(0.2, 0.2, 0.2)
- laser.BrickColor = BrickColor.new("Crimson")
- laser.Anchored = true
- laser.CanCollide = false
- laser.Locked = true
- laser.CFrame = script.Parent.CFrame
- laser.Parent = game.Workspace
- local maxDistance = 400
- local curDistance = 0
- local stepDistance = 4
- local stepWait = 0
- local currentPos = script.Parent.Position
- local currentNormal = game.workspace.LeFireFire.CFrame.lookVector
- local function Step(overrideDistance)
- -- Cast ray:
- local ray = Ray.new(currentPos, currentNormal * (overrideDistance or stepDistance))
- local hit, pos, norm = game.Workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent})
- -- Update laser position:
- laser.Size = Vector3.new(0.4, 0.4, (pos - currentPos).magnitude)
- laser.CFrame = CFrame.new(currentPos:lerp(pos, 0.5), pos)
- local oldPos = currentPos
- currentPos = pos
- if (hit) then
- -- r = d - 2(d DOT n)n
- -- Reflect:
- local reflect = (currentNormal - (2 * currentNormal:Dot(norm) * norm))
- currentNormal = reflect
- Step(stepDistance - (pos - oldPos).magnitude)
- return
- end
- curDistance = (curDistance + (pos - oldPos).magnitude)
- -- Apply fade effect to laser as it approaches max distance from < 75 studs:
- if (curDistance > (maxDistance - 75)) then
- local d = (curDistance - (maxDistance - 75)) / 75
- laser.Transparency = d
- end
- -- Recurse if max distance not reached:
- if (curDistance < maxDistance) then
- wait(stepWait)
- Step()
- end
- end
- Step()
- -- Done! Destroy laser:
- laser:Destroy()
- end
- end
- Shoot() -- Fire shot!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement