Camera Positions

Hi,

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)
1 Like

I think the issue is that you are trying to change the camera’s CFrame as well as the FieldOfView.
Try removing the:

workspace.CurrentCamera.CFrame = defaultShot

And The

workspace.CurrentCamera.CFrame = slideShot

In both of the if statments.

1 Like

What exactly is the issue you’re having here? I tried out your script and it seems to work alright?

Is the camera being moved to another position when you tested? It’s meant to offset it by the value sidePos

Here’s a quick video of what’s not meant to happen:
https://gyazo.com/e84ac561bfc24679e3551950b6c11609

As you can probably tell, the camera should be moving to another position. What’s weirder, is that there aren’t any errors in the Dev Console.

Oh sorry I misinterpreted what you were asking…

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!

1 Like

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)