How to rotate a camera around a model

I am making a shop GUI. Now I want the player to look at the Sword in all directions. In other words. I want the viewport frame camera to rotate around the model? how do I do that?

2 Likes
-- Say we have a variable, that's the primary part of the Sword I'll call it Sword.
local cframe = Sword.CFrame * CFrame.Angles(0, 0, 0) * CFrame.new(0, 0, -5) 
--  Change the angles accordingly, and the -5 should be distance from the objects center outwards.
-- Once you have that, you want to take that position and have it face the position of the sword, and then set the Viewport's camera cframe to that new cframe.
cframe = CFrame.new(cframe.p, Sword.Position)
Viewport.Camera.CFrame = cframe;
18 Likes

Thank You for your contribution, I will try it out!

1 Like

I took the time to set up an example of my code in action,
--Setup

and then the code was slightly modified

local Viewport = script.Parent.ViewportFrame;
local Dummy = Viewport:WaitForChild("Dummy");
local Sword = Dummy:WaitForChild("HumanoidRootPart");

local Camera = Instance.new("Camera")
Camera.Parent = Viewport
Viewport.CurrentCamera = Camera

local c = 0;

game:GetService("RunService").Heartbeat:Connect(function()
	-- Say we have a variable, that's the primary part of the Sword I'll call it Sword.
	local cframe = Sword.CFrame * CFrame.Angles(0, math.rad(c), 0) * CFrame.new(0, 0, -5) 
	--  Change the angles accordingly, and the -5 should be distance from the objects center outwards.
	-- Once you have that, you want to take that position and have it face the position of the sword, and then set the Viewport's camera cframe to that new cframe.
	cframe = CFrame.new(cframe.p, Sword.Position)
	Viewport.CurrentCamera.CFrame = cframe;
	
	c = c + 3;
end)
38 Likes

Yes I did figure it out using your example code. Thanks Alot. Also do you know how to cast shadows in Viewport Frame?

As far as I’m aware of, casting shadows are still not a thing in viewport frames.

Blockquote
A ViewportFrame is a type of GUI that can render 3D objects inside its bounds. This is a great way to display 3D objects/models in a 2D GUI space like a ScreenGui . At the moment, no shadow or post effects are available. Neon and Glass materials will be rendered on lowest quality.

according to the api page, located below

4 Likes

Thanks for the info!! It helped me alot!