ViewPortFrame issue

So there is something I don’t understand, inside my MouseEnter event I have this code run, which I ripped from another tutorial page.

	viewportCamera.FieldOfView = 40
	local cameraGoal = {
		CFrame = CFrame.new(Vector3.new(0, 6, 4), part.Position)
	}
	local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
	local tween = TweenService:Create(viewportCamera, tweenInfo, cameraGoal)
	tween:Play()

I don’t understand how this rotates the camera, shouldn’t it just put the camera to that X, Y, and Z on a 2D view? Because the same code runs after a 2 second wait (different dimensions) but it shows it on a 2D plane, yet when the mouse enter event runs it actually rotates the camera to view the top of this part.

I want the rotate to happen, but I can’t seem to get the camera closer to the part, if I lower the values used in the tween then the rotate doesn’t happen. I tried changing the camera FieldOfView on MouseEnter, but it only changes it once I return back to my original camera view via the MouseLeave event. Any ideas how to fix this?

local TweenService = game:GetService("TweenService")

task.wait(2)
print("waited")
local viewportFrame = script.Parent;
part = workspace.Hair
part.Position = Vector3.new(0, 0, 0)
part.Parent = viewportFrame
local cameraOffset = Vector3.new(0, .5, 2)
local viewportCamera = Instance.new("Camera")
viewportFrame.CurrentCamera = viewportCamera
viewportCamera.Parent = viewportFrame
viewportCamera.CFrame = CFrame.new(Vector3.new(0, .5, 2), part.Position)
local rotatedCFrame = CFrame.Angles(math.rad(15), 0, 0)
rotatedCFrame = CFrame.new(part.Position) * rotatedCFrame
viewportCamera.CFrame = rotatedCFrame:ToWorldSpace(CFrame.new(cameraOffset))

viewportFrame.MouseEnter:Connect(function(x, y)
viewportCamera.FieldOfView = 40
local cameraGoal = {
CFrame = CFrame.new(Vector3.new(0, 6, 4), part.Position)
}
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local tween = TweenService:Create(viewportCamera, tweenInfo, cameraGoal)
tween:Play()
end)

viewportFrame.MouseLeave:Connect(function(x, y)
local cameraGoal = {
CFrame = CFrame.new(Vector3.new(0, .5, 2), part.Position)
}
local tweenInfo = TweenInfo.new(2, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local tween = TweenService:Create(viewportCamera, tweenInfo, cameraGoal)
tween:Play()
end)
1 Like

Sorry I couldn’t help you, I don’t know anything about scirpting, but I’ll up your topic so maybe people can help you.

1 Like

If you want to use tweenservice then you may want to rotate a part instread of rotating camera around it.

it rotates it because the camera is moving while still facing the object
so its not really rotating it rather the camera is rotating down
if you just want the camera to zoom out a bit set the 6 to 0 in the vector3.new i have no way of testing this but it may be the answer

Oh I see, I didn’t know view port always faces the part. Makes sense thanks