Specific viewing position for viewport camera

Hey!

I have a ViewportFrame inside of a GUI. I have a part in the ViewportFrame that I am trying to look at from the top. Inside of a LocalScript I have written:

local ViewportFrame = script.Parent
local Part = ViewportFrame.Part
local Camera = Instance.new("Camera")

ViewportFrame.CurrentCamera = Camera
Camera.Parent = ViewportFrame

local PosX = Part.CFrame.Position.X
local PosY = Part.CFrame.Position.Y
local PosZ = Part.CFrame.Position.Z

Camera.CFrame = CFrame.new(PosX, PosY + 5, PosZ)

I have tried looking at the documentation and online, however, I have found nothing to work.

Any ideas?

You can use CFrame.lookAt

local ViewportFrame = script.Parent
local Part = ViewportFrame.Part
local Camera = Instance.new("Camera")

ViewportFrame.CurrentCamera = Camera
Camera.Parent = ViewportFrame

local Pos = Part.CFrame.Position 

Camera.CFrame = CFrame.lookAt(Pos + Vector3.new(0, 5, 0), Pos)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.