I’ve attempted to make a simple zoom function that offsets the camera likewise to the ShiftLock offset (as seen in the script below). Apologies for my most likely poorly optimised script, I’m way out of my depth here, and I tried to do this with minimal tutorials.
The script is a LocalScript inside StarterGUI
The zoom function works fine, making CurrentCamera.FieldOfView decrease and increase accordingly, however, I’m having trouble with the camera position.
I’ve looked for solutions, but was unable to find any similar issues. Any help would be appreciated!
-- Positions
local sidePos = Vector3.new(0, 100, 100)
local defaultPos = Vector3.new(0, 0, 0)
-- Camera
local sideShot = CFrame.new(sidePos)
local defaultShot = CFrame.new(defaultPos)
-- Default Pos
game.Players.LocalPlayer:GetMouse().KeyUp:connect(function(key)
if key =="z" then
workspace.CurrentCamera.FieldOfView = 50
workspace.CurrentCamera.CFrame = defaultShot
end
end)
-- Zoom Pos
game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key)
if key =="z" then
workspace.CurrentCamera.FieldOfView = 15
workspace.CurrentCamera.CFrame = sideShot
end
end)
Was something like this what you wanted?? If you’re still using the default character scripts, you have to set the camera’s cframe every frame for it to actually change position.
-- Positions
local sidePos = Vector3.new(0, 100, 1000)
local defaultPos = Vector3.new(0, 0, 0)
-- Camera
local sideShot = CFrame.new(sidePos)
local defaultShot = CFrame.new(defaultPos)
local z_key_down = false
-- Default Pos
game.Players.LocalPlayer:GetMouse().KeyUp:connect(function(key)
if key =="z" then
workspace.CurrentCamera.FieldOfView = 50
z_key_down = false
end
end)
-- Zoom Pos
game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key)
if key =="z" then
workspace.CurrentCamera.FieldOfView = 15
z_key_down = true
end
end)
-- Run every frame
game:GetService("RunService").RenderStepped:Connect(function()
if z_key_down then
workspace.CurrentCamera.CFrame = sideShot
else
workspace.CurrentCamera.CFrame = defaultShot
end
end)
That’s on the right track, thanks. I’m trying to get it to follow the player and mimic shift lock. At the moment, it’s just moving the camera but not following the player. I’ll take a look into how to modify it, unless you have a solution. Thanks!
To make it follow the player, you would want to take the player character’s cframe and then multiply that by your offset cframe then give the result to the camera cframe. (you might want to use smaller values than 100 btw for this case)