Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local RunService = game:GetService("RunService")
- local PlayerService = game:GetService("Players")
- local UserInputService = game:GetService("UserInputService")
- local TweenService = game:GetService("TweenService")
- local SoundService = game:GetService("SoundService")
- local DebrisService = game:GetService("Debris")
- local LocalPlayer = PlayerService.LocalPlayer
- local PlayerGui = LocalPlayer.PlayerGui
- local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
- local Humanoid : Humanoid = Character:FindFirstChildWhichIsA("Humanoid")
- local Flashlight = workspace:WaitForChild("flashlight")
- local camera = workspace.CurrentCamera
- local sin = math.sin
- local rad = math.rad
- local cos = math.cos
- local abs = math.abs
- local random = Random.new()
- local rate = .0075
- local running = false
- local offsetrunning = false
- local steprate = 20
- local cooldown = 0
- local stepoffset = 0
- local positive = false
- local flashlightOn = false
- local zOffset = 0
- local crouchingOffset = 0
- local idle = false
- local proceedingToCrouch = false
- local crouching = false
- local footstepTable : {string} = {
- [Enum.Material.Fabric] = {
- "rbxassetid://6240702531",
- "rbxassetid://133705377"
- },
- [Enum.Material.Rock] = {
- "rbxassetid://90507702118699",
- "rbxassetid://135712042029119",
- "rbxassetid://98172042741214"
- }
- }
- function tweenSprinting(toggle: boolean)
- local info = TweenInfo.new(0.75, Enum.EasingStyle.Quad, Enum.EasingDirection.In)
- if Humanoid.MoveDirection.Magnitude > 0 and not idle then
- if toggle then
- if not running then
- running = true
- TweenService:Create(Humanoid, info, {WalkSpeed = 13}):Play()
- TweenService:Create(SoundService.windcamera, info, {Volume = 0.75}):Play()
- end
- else
- if running then
- running = false
- TweenService:Create(Humanoid, info, {WalkSpeed = 6}):Play()
- TweenService:Create(SoundService.windcamera, info, {Volume = 0}):Play()
- rate = 0.02
- end
- end
- else
- if running then
- running = false
- TweenService:Create(Humanoid, info, {WalkSpeed = 6}):Play()
- TweenService:Create(SoundService.windcamera, info, {Volume = 0}):Play()
- rate = 0.02
- end
- end
- end
- function toggleFlashlight()
- local maxIndex = 15
- for i = 1, maxIndex do
- zOffset += 0.005
- task.wait(maxIndex / 500)
- end
- local flashlightSound = Instance.new("Sound")
- flashlightSound.Parent = Flashlight
- flashlightSound.Volume = 0.5
- flashlightSound.SoundId = "rbxassetid://78509455631020"
- if flashlightOn then
- flashlightSound.PlaybackSpeed = 0.9
- flashlightOn = false
- PlayerGui.MainUI.Timer.Flashlight.Visible = false
- TweenService:Create(Flashlight.SpotLight, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {Brightness = 0}):Play()
- TweenService:Create(Flashlight.Buzzing, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {Volume = 0}):Play()
- TweenService:Create(Flashlight.Spot2, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {Brightness = 0}):Play()
- else
- flashlightSound.PlaybackSpeed = 1
- flashlightOn = true
- PlayerGui.MainUI.Timer.Flashlight.Visible = true
- TweenService:Create(Flashlight.SpotLight, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {Brightness = 2}):Play()
- TweenService:Create(Flashlight.Buzzing, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {Volume = .1}):Play()
- TweenService:Create(Flashlight.Spot2, TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {Brightness = 0.5}):Play()
- end
- flashlightSound:Play()
- DebrisService:AddItem(flashlightSound, flashlightSound.TimeLength + 0.3)
- for i = 1, maxIndex do
- zOffset -= 0.005
- task.wait(maxIndex / 500)
- end
- end
- --[[function toggleCrouching(toggle)
- repeat task.wait() until proceedingToCrouch == false
- if crouching == toggle then return end
- local maxIndex = 200
- local targetOffset = 2
- proceedingToCrouch = true
- print("being called")
- if toggle then
- for i = 1, maxIndex do
- crouchingOffset += targetOffset / maxIndex
- task.wait(targetOffset / (maxIndex * 5))
- end
- crouchingOffset = targetOffset
- crouching = true
- else
- for i = 1, maxIndex do
- crouchingOffset -= targetOffset / maxIndex
- task.wait(targetOffset / (maxIndex * 5))
- end
- crouchingOffset = 0
- crouching = false
- end
- proceedingToCrouch = false
- end]]
- function sendFootstep()
- local floorMaterial = footstepTable[Humanoid.FloorMaterial]
- if floorMaterial then
- local id = floorMaterial[math.random(1, #floorMaterial)]
- local newSound = Instance.new("Sound")
- newSound.Parent = SoundService
- newSound.Volume = 0.45
- newSound.SoundId = id
- newSound.PlaybackSpeed = Random.new():NextNumber(.2, .4)
- if running then
- newSound.PlaybackSpeed = Random.new():NextNumber(.4, .6)
- newSound.Volume = .65
- end
- newSound:Play()
- DebrisService:AddItem(newSound, 3)
- end
- end
- function updateCamera(deltaTime: number)
- Flashlight.CFrame = camera.CFrame
- if UserInputService:IsKeyDown(Enum.KeyCode.LeftShift) then
- if Humanoid.MoveDirection.Magnitude > 0 and not crouching then
- tweenSprinting(true)
- else
- tweenSprinting(false)
- end
- else
- tweenSprinting(false)
- if rate > 0.0075 then
- rate -= 0.0002
- end
- end
- if UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) then
- if not running then
- --task.spawn(toggleCrouching, true)
- end
- else
- --task.spawn(toggleCrouching, false)
- end
- if Humanoid.MoveDirection.Magnitude > 0 then
- idle = false
- cooldown += deltaTime
- if stepoffset > 0 then
- stepoffset -= 0.002
- else
- stepoffset = 0
- end
- if cooldown >= steprate then
- cooldown = 0
- stepoffset = .02
- sendFootstep()
- end
- else
- idle = true
- end
- if Humanoid.MoveDirection.Magnitude == 0 then
- local bobbleX = rad(cos(tick() * 3) * .025)
- local bobbleY = rad(abs(sin(tick()) * 1.4 / 2.3)) * .035
- local bobbleZ = rad(cos(tick() * 3.5 / 1.5) * .04) + zOffset
- local newCFrame = camera.CFrame * CFrame.Angles(bobbleX, bobbleY, bobbleZ)
- camera.CFrame = newCFrame
- elseif running then
- steprate = 0.26
- local bobbleX = rad(cos((tick()) * 13 / 1.4) * .2)
- local bobbleY = rad(sin((tick()) * 1.4 / 2.3) * .1)
- local bobbleZ = (rad(cos((tick()) * 7 / 1.4) * 0.7) + (random:NextNumber(-rate* 1.05, rate* 1.05))) + zOffset
- if math.random(1, 2) == 1 then
- if not positive then
- positive = true
- bobbleX += (random:NextNumber(-rate * 2.1, rate * 2.1)) - (stepoffset * 1.75)
- else
- positive = false
- bobbleX += (random:NextNumber(-rate * 2, rate * 2)) + (stepoffset * 1.75)
- end
- bobbleY += (random:NextNumber(-rate *1.6, rate*1.6))
- end
- local newCFrame = camera.CFrame * CFrame.Angles(bobbleX, bobbleY, bobbleZ)
- camera.CFrame = newCFrame
- elseif proceedingToCrouch then
- local bobbleX = rad(cos((tick()) * 10 / 1.5) * .02)
- local bobbleY = rad(sin((tick()) * 1.4 / 2.3) * .01)
- local bobbleZ = rad(cos((tick()) * 6 / 1.5) * 0.15) + zOffset
- if math.random(1, 3) == 1 then
- if not positive then
- positive = true
- bobbleX += (random:NextNumber(-rate* 1.2, rate * 1.2))
- else
- positive = false
- bobbleX += (random:NextNumber(-rate, rate))
- end
- bobbleY += (random:NextNumber(-rate/1.5, rate/1.5))
- end
- local newCFrame = camera.CFrame * CFrame.Angles(bobbleX, bobbleY, bobbleZ)
- else
- steprate = 1.16
- local bobbleX = rad(cos((tick()) * 10 / 1.5) * .02)
- local bobbleY = rad(sin((tick()) * 1.4 / 2.3) * .01)
- local bobbleZ = rad(cos((tick()) * 6 / 1.5) * 0.15) + zOffset
- if math.random(1, 3) == 1 then
- if not positive then
- positive = true
- bobbleX += (random:NextNumber(-rate/1.1, rate/1.1)) - stepoffset
- else
- positive = false
- bobbleX += (random:NextNumber(-rate/1.1, rate/1.1)) + stepoffset
- end
- bobbleY += (random:NextNumber(-rate/1.8, rate/1.8))
- end
- local newCFrame = camera.CFrame * CFrame.Angles(bobbleX, bobbleY, bobbleZ)
- camera.CFrame = newCFrame
- end
- local divide = 7
- local offset = Vector3.new(random:NextNumber(-rate / divide, rate / divide), random:NextNumber(-rate / divide, rate / divide), 0)
- Humanoid.CameraOffset = Vector3.new(0, 3 - crouchingOffset, 0)
- --[[if math.random(1, 10) == 1 and not offsetrunning then
- offsetrunning = true
- for i = 0, .25, .025 do
- Humanoid.CameraOffset = Humanoid.CameraOffset:Lerp(offset, .40) + Vector3.new(0, 1.25 - crouchingOffset, 0)
- task.wait(.01)
- end
- offsetrunning = false
- end]]
- end
- UserInputService.InputBegan:Connect(function(input: InputObject, gameProcessedEvent: boolean)
- if gameProcessedEvent then return end
- if input.KeyCode == Enum.KeyCode.F then
- if not running then
- toggleFlashlight()
- end
- end
- end)
- RunService.RenderStepped:Connect(updateCamera)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement