Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local LP = game:GetService("Players").LocalPlayer
- local Char = LP.Character
- local Camera = workspace.CurrentCamera
- local RenderStepped = game:GetService("RunService").RenderStepped
- local OverrideNum = 1
- local Operating = false
- Camera.CameraType = "Scriptable"
- function TweenCamera(EndPos, EndFocus, Override, WaitForCompletion, TweenTime, StayFocused, useSin)
- local function TweenFunc()
- if Override and Operating then
- OverrideNum = OverrideNum+1
- elseif Operating then
- return false
- end
- Operating = true
- local OverrideID = OverrideNum
- local Interval = (1/(TweenTime/RenderStepped:wait()))
- local StartCF = Camera.CFrame
- local EndCF = CFrame.new(EndPos, EndFocus)
- for i = 0, 1, Interval do
- i = useSin and math.sin(math.pi/2*i) or i
- local newCamCF = StartCF:lerp(EndCF, i)
- Camera.CFrame = (not StayFocused and newCamCF) or CFrame.new(newCamCF.p, EndFocus)
- RenderStepped:wait() --Use RenderStepped for anything camera related!!!
- if OverrideNum ~= OverrideID then
- return false
- end
- end
- Operating = false
- Camera.CFrame = EndCF
- return true
- end
- if WaitForCompletion then
- TweenFunc()
- else
- coroutine.resume(coroutine.create(TweenFunc))
- end
- end
- ---EXAMPLE USAGE---
- local StartCamOffset = Char.Head.CFrame:toObjectSpace(Camera.CFrame) --(Gets original camera offset to use later)
- TweenCamera(Vector3.new(60, 60, 60), Vector3.new(10, 60, 70), true, true, 3, false, true)
- --Key: Description [Parameter]
- --Tweens position to Vector3.new(60, 60, 60) pointing towards Vector3.new(10, 60, 70) in a half sine wave effect [1] [2] [7]
- --Doesn't always point towards Vector3.new(10, 60, 70) (focus will tween too) [6]
- --Yields return until the 3 seconds of interpolation has completed [4] [5]
- --The interpolation can be overriden at any time by calling the function midway [3]
- TweenCamera(Vector3.new(40, 50, 30), Vector3.new(-30, 40, -50), true, true, 2, false, true)
- TweenCamera((Char.Head.CFrame * StartCamOffset).p, Char.Head.CFrame.p, true, true, 4, false, false) --Tweens back to the original offset
- Camera.CameraSubject = Char.Humanoid
- Camera.CameraType = "Custom"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement