How to position a model directly infront of the camera in a viewport frame?

I need help to put my model infront of the camera for some reason it just looks like this
image
just very far away and not even infront

its in a world like this:

this is the part of the code:

local viewport = button:WaitForChild("ViewportFrame")
			
			
			
			local viewportmodel = tower:Clone()
			viewportmodel.Parent = viewport.WorldModel
			
			
			
			local viewportcamera = Instance.new("Camera")
			viewportcamera.Parent = viewport
			
			local pos = (CFrame.new(camera.CFrame.Position) + camera.CFrame.LookVector * 5) * CFrame.Angles(20,10,5)
			viewportmodel:PivotTo(pos)
			viewport.CurrentCamera = viewportcamera

and there are no errors, can someone please help me?

Hey! When using viewports, I like having two parts in the workspace: one for the camera and one for the model. Make sure you set a primaryPart to the model. Then, when loading the model in the viewportframe, you can use :PivotTo() on the model and pass one of the part’s cframe as an argument, and then set the camera’s cframes to the other part’s cframe.

If you’d rather do it through scripting, you can use viewportcamera.CFrame.LookVector * 5 to position the model 5 studs away from where the camera is in the direction it is looking. Then, you could use CFrame.lookAt to make the model face the camera. Let me know if this was helpful :slight_smile:

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