Making a planet game, for my custom camera script (it’s like the Minecraft dungeons camera system), and using Egomoose’s gravity system which make the character be able to walk on the planet/sphere, I want my camera to track the player’s humanoidrootpart or head or torso’s orientation for the camera orientation, but since I’m so terrible with CFrames, I don’t know how.
local Players = game:GetService('Players')
local RunService = game:GetService('RunService')
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local currentZoom = 30
local currentX = 63.84100000000000108
local currentY = 42.5
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.FieldOfView = 20
RunService:BindToRenderStep('Camera', Enum.RenderPriority.Camera.Value, function()
local subject = workspace.CurrentCamera.CameraSubject
if subject then
if subject:IsA('Humanoid') then
subject = subject.Parent:FindFirstChild('HumanoidRootPart') or subject.RootPart
workspace.CurrentCamera.CFrame = CFrame.new(subject.Position + Vector3.new(currentX, currentY, currentZoom), subject.Position)
else
workspace.CurrentCamera.CFrame = subject.CFrame
end
end
end)
Not sure if this helps at all, but this is some code that I used at one point when messing around with a top-down 2.5D camera type thing.
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local cameraOffset = Vector3.new(90, 90, 0)
camera.CameraType = Enum.CameraType.Scriptable
local function onRenderStep()
if player.Character then
local playerPosition = player.Character.HumanoidRootPart.Position
local cameraPosition = playerPosition + cameraOffset
camera.CoordinateFrame = CFrame.new(cameraPosition, playerPosition)
end
end
RunService:BindToRenderStep("Camera", Enum.RenderPriority.Camera.Value, onRenderStep)
Like I said, no clue if this is of any help, just posting it here because I used this code for a similar thing lol.