Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

how to make the camera focus on the player?

Asked by
Grazer022 128
3 years ago

local script inside StarterPlayerScripts

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
local hrp = character:WaitForChild(“HumanoidRootPart”)

local RS = game:GetService(“RunService”)

local camPart = Instance.new(“Part”)
camPart.Parent = character 
camPart.Name = “CameraPart”
camPrt.Transparency = 1 

local function onLockedUpdate()
   camPart.CFrame = CFrame.new(hrp.Position) * CFrame.new(30,50,15)
   camera.CFrame = camPart.Position
end

RS:BindToRenderStep(“Camera”,Enum.RenderPriority.Camera.Value,onLockedUpdate)

the thing is, the camera won’t look at the player. Instead, the camera just looks forward. How do I make it that the camera looks at the player? Thanks!

1 answer

Log in to vote
0
Answered by
tjtorin 172
3 years ago
Edited 3 years ago

I'm not 100% sure this is what you were asking for as it was kind of a confusing question but I think this could be the answer.

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
local hrp = character:WaitForChild("HumanoidRootPart")

local RS = game:GetService("RunService")

local function onLockedUpdate()
    local playerPos = hrp.Position
    local cameraPos = playerPos + Vector3.new(15, 25, 7.5)
    camera.CoordinateFrame = CFrame.new(cameraPos, playerPos)
end

RS:BindToRenderStep("Camera",Enum.RenderPriority.Camera.Value,onLockedUpdate)
0
CFrame is CoordinateFrame in short Grazer022 128 — 3y
0
Oh :| tjtorin 172 — 3y
Ad

Answer this question