Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sp = script.Parent
- local player = game.Players.LocalPlayer
- local runService = game:GetService('RunService')
- local cam = game.Workspace.CurrentCamera
- local p = game.Workspace:FindFirstChild('CameraPart') or Instance.new('Part')
- p.Name = 'CameraPart'
- p.TopSurface = 'Smooth'
- p.BottomSurface = 'Smooth'
- p.FrontSurface = 'Hinge'
- p.Anchored = true
- p.CanCollide = false
- p.Parent = game.Workspace
- local stickyness = 0.01
- local desiredHeight = 5
- local desiredDist = 25
- local maxDist = 2
- local minDist = 0
- local function swait(a)
- if a and a>.0333 then
- wait(a)
- else
- runService.RenderStepped:wait()
- end
- end
- while true do
- swait()
- local character = player.Character
- if character and character.Parent == game.Workspace then
- local target = character:FindFirstChild('Torso')
- if target then
- cam.CameraType = 'Scriptable'
- local vectorAway = ((cam.CoordinateFrame.p - target.Position) * Vector3.new(1,0,1)).unit
- if vectorAway.x ~= vectorAway.x then
- vectorAway = Vector3.new(1,0,0)
- end
- local desiredPos = target.Position + vectorAway * desiredDist + Vector3.new(0,desiredHeight,0)
- local resultPos = desiredPos * stickyness + cam.CoordinateFrame.p * (1-stickyness)
- local resultVec = resultPos - target.Position
- local resultUnitVec = (resultVec).unit
- if resultUnitVec.x ~= resultUnitVec.x then
- resultUnitVec = Vector3.new(1,0,0)
- end
- local gotClamped = false
- if resultVec.magnitude > maxDist then
- resultVec = resultUnitVec * maxDist
- gotClamped = true
- elseif resultVec.magnitude < minDist then
- resultVec = resultUnitVec * minDist
- gotClamped = true
- end
- if gotClamped then
- cam.CoordinateFrame = CFrame.new(target.Position+resultVec,target.Position)
- else
- cam.CoordinateFrame = CFrame.new(resultPos,target.Position)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement