Help with camera positioning?

Hello! I’m currently working on a project where I need to be able to position the camera within a viewport frame in a similar manner to that of the roblox marketplace; however, I have been unable to do so as I am unable to achieve the correct positioning and orientation.

Here is the code I am currently using:

local Cam = Instance.new("Camera")
Cam.CameraType = Enum.CameraType.Scriptable
Cam.Parent = View

local Scale = Obj:GetExtentsSize().Magnitude
Scale = math.pow(Scale, 0.5) -- Square rooted because it was too far away otherwise
Cam.CFrame =  CFrame.lookAt(Obj:GetPivot().Position+(Vector3.new(-1,.5,-1.5)*Scale), Obj:GetPivot().Position)

This is what that code produces:
My Result:
1Keeth Noob View

Goal (Marketplace Image)
Noob Reference

My Result
1Keeth Home View

Goal (Marketplace Image)
Home Reference

If you have any idea how I can correct this, please let me know! Anything is appreciated.

Thanks for reading :slight_smile:
Merry Christmas!

I got a couple of Ideas.

You can set it by the studio’s camera.
Or you could set it by a set Position or off of another part’s Position.

  • Set by Studio’s camera you wanna set the ViewFrame’s current camera to the Camera in workplace, then move your camera to the angle/pos you want. You can also see the pos update in the viewFrame. Once you get the spot, Duplicate the camera and set the viewFrame’s camera into the viewFrame. As shown below :arrow_down:

  • Set by Position is to go by another part like a camera you would make for a menu. Add a part and angle/pos it like a camera then set the camera’s position by the parts. As shown below :arrow_down:

ExampleGif

Update ViewFrame's Camera's Position (from Gif)
camPart:GetPropertyChangedSignal("CFrame"):Connect(function()
	Cam.CFrame = camPart.CFrame
end)

1 Like