Lock camera to a part and then have it follow a player?
Asked by
7 years ago Edited 7 years ago
Ive been reading all over the wiki and trying to figure this out because it has to be possible.
I want the camera to lock to a part, and then basically rotate around the part according to where the player is. Do you know what I mean? Like I want the camera to follow the player but stay locked to the part.
So ive tried 3 different scripts and they all do different things but not the thing I want them to do.
Script 1 (This script doesnt work at all really)
01 | local RunService = game:GetService( "RunService" ) |
02 | local Players = game:GetService( "Players" ) |
04 | local OFFSET = Vector 3. new( 40 , 40 , 40 ) |
05 | local FIELD_OF_IEW = 40 |
07 | local player = Players.LocalPlayer |
08 | local camera = game.Workspace.CurrentCamera |
12 | camera.FieldOfView = FIELD_OF_VIEW |
14 | local function onRenderStep() |
15 | local character = player.Character |
17 | local humanoidRootPart = player:FindFirstChild( "HumanoidRootPart" ) |
18 | if humanoidRootPart then |
19 | local playerPosition = humanoidRootPart.Position |
20 | local cameraPosition = playerPosition + OFFSET |
21 | camera.CoordinateFrame = CFrame.new(cameraPosition, playerPosition) |
26 | RunService:BindToRenderStep( "Camera" , Enum.RenderPriority.Camera.Value, onRenderStep) |
Script 2 (This locks the camera to the player but not to another part)
01 | local Camera = game.Workspace.CurrentCamera |
02 | local Player = game.Players.LocalPlayer |
08 | local Character = Player.Character |
09 | local Player_Torso = Character.UpperTorso |
13 | Camera.CameraType = Enum.CameraType.Scriptable |
14 | Camera.CameraSubject = Player_Torso |
16 | game:GetService( "RunService" ).RenderStepped:connect( function () |
17 | if Player.Character and Player.Character:FindFirstChild( 'UpperTorso' ) then |
18 | Camera.CFrame = CFrame.new(Player_Torso.CFrame.X, Player_Torso.CFrame.Y + 2 , Player_Torso.CFrame.Z + 14 ) |
Script 3 (This locks the camera to a part but then the camera doesnt follow the player)
01 | local Camera = game.Workspace.CurrentCamera |
02 | local Player = game.Players.LocalPlayer |
03 | local Lock = game.Workspace.CameraLock |
07 | Camera.CameraType = Enum.CameraType.Scriptable |
09 | game:GetService( "RunService" ).RenderStepped:connect( function () |
10 | if Player.Character and Player.Character:FindFirstChild( 'Humanoid' ) then |
11 | Camera.CameraSubject = Lock |
12 | Camera.CFrame = CFrame.new(Lock.CFrame.X, Lock.CFrame.Y + 5 , Lock.CFrame.Z + 20 ) |
Thank you for youre time if you want some more info please do ask.
I also just recently tried this one but it doesnt work either.. I think I am getting close
01 | local Camera = game.Workspace.CurrentCamera |
02 | local Lock = game.Workspace.CameraLock |
04 | local Player = game.Players.LocalPlayer |
05 | local Character = Player.Character |
06 | local Player_Head = Character.UpperTorso |
10 | Camera.CameraType = Enum.CameraType.Scriptable |
12 | game:GetService( "RunService" ).RenderStepped:connect( function () |
13 | if Player.Character and Player.Character:FindFirstChild( 'Humanoid' ) then |
14 | Camera.CameraSubject = Lock |
15 | Camera.Focus = CFrame.new(Player_Head.CFrame.X + 0 , Player_Head.CFrame.Y + 0 , Player_Head.CFrame.Z + 0 ) |
16 | Camera.CFrame = CFrame.new(Lock.CFrame.X, Lock.CFrame.Y + 5 , Lock.CFrame.Z + 20 ) |