Basically have a part which changes the CameraMode to LockFirstPerson and when I’m done I wish to change it back to Classic. This is all fine except that the camera is still in the characters head and I have to scroll out. How to I get the camera’s offset so it can be set after I restore the CameraMode back to classic?
You could store it to a local variable in a Local Script you would need to save the CurrentCamera.CFrame then when you no longer need it set the CurrentCamera’s CameraSubject Property to Custom and set the currentCamera’s CFrame to the local variable.
You can also use TweenService if you want to tween it going from first peson to third person and once the tween has completed set the CurrentCamera.SubjectType to Custom
Thought about that, tried numerous ways and each time without manually setting the camera’s cframe I couldn’t work out to how to set it up. I wanted to capture where the camera currently was at that particular moment in relation to where the character was but I can’t find any property for it. This leaves me with manually setting it afterwards which is fine but I was hoping to get whereever the players camera was at that time, perhaps it was close to the character or zoomed out. The CameraOffset always seemed to be 0,0,0 so that was no help and while I was able to change it back to Custom from FirstPerson the camera just stayed in the characters head until I scrolled out. I think this means I have to set up a customizable camera so I can easily find the current camera’s location before changing it essentially rewriting Roblox’s camera system.
Wait so are you trying to force the player to zoom out? You can just set minimum zoom to a high number, then set it back to default, and it will make the player force zoom out. There’s probably a better way you can it, but I’ve done this before and it works.
This will set the zoom… and you can get the hrp magnitude difference from the Camera.
local player: Player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp=character:WaitForChild("HumanoidRootPart")
function setZoom(ply, min, max, set)
ply.CameraMinZoomDistance=set
ply.CameraMaxZoomDistance=set task.wait(0.1)
ply.CameraMinZoomDistance=min
ply.CameraMaxZoomDistance=max
end
setZoom(player, 4, 9, 6)
task.wait(3)
local cam = workspace.CurrentCamera
local zoom = (cam.CFrame.Position - hrp.Position).Magnitude
print(zoom)
This may help.
It basically calculates the offset of the camera to another point. You can use this to move the player’s camera back by setting its cframe.
Yep that’s exactly what I did but in doing so the players ability to now zoom in and out is not available/working. Still trying to find the answer.
local player = game:GetService("Players").LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
local cameraOrigin
local minZoom = player.CameraMinZoomDistance
local maxZoom = player.CameraMaxZoomDistance
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local function tweenCameraZoom(zoom: number)
local zoomTween = TweenService:Create(player, tweenInfo, {
CameraMinZoomDistance = zoom,
CameraMaxZoomDistance = zoom
})
zoomTween:Play()
end
character:GetAttributeChangedSignal("IsFirstPerson"):Connect(function()
if character:GetAttribute("IsFirstPerson") then
cameraOrigin = camera.CFrame
tweenCameraZoom(player.CameraMinZoomDistance) -- Zoom into first person
player.CameraMode = Enum.CameraMode.LockFirstPerson
else
if cameraOrigin then
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = cameraOrigin
tweenCameraZoom(10) -- Zoom out to a reasonable spot?
camera.CameraType = Enum.CameraType.Custom
player.CameraMinZoomDistance = minZoom
player.CameraMaxZoomDistance = maxZoom
task.wait() --wait a frame?
player.CameraMode = Enum.CameraMode.Classic
end
end
end)
I think I know what the issue is, I think that it isn’t waiting for the tween to finish.
So it’s basically locking zoom, unlocking zoom, instantly locking zoom again, finishing the tween, and the zoom stays locked.
So yeah just have it wait for the tween to be finished before unlocking the zoom.