Trouble getting updated camera CFrame after turning on shiftlock

  1. What do you want to achieve? Keep it simple and clear!
    I’m making a gun system and i need to cast a ray towards specific point from position of the screen
    I need to get a Position of camera after turning on shiftlock on local script

  2. What is the issue? Include screenshots / videos if possible!
    Camera Position does not update for scripts when turning on shiftlock

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Tried using workscape.Camera, workspace.CurrentCamera, nothing works, couldn’t find anything related on the forums

-- Local script:
warn("Local Script camera Position: "..tostring(workspace.CurrentCamera.CFrame.Position))

-- Command Bar:
warn("Command Bar camera Position: "..tostring(workspace.CurrentCamera.CFrame.Position))

It’s completely the same but for some reason local script does not get updated CFrame of camera when enabling shiftlock

local script context:

	local Position = Camera:ViewportPointToRay(Camera.ViewportSize.X/2,0+Camera.ViewportSize.Y/4,2000)
	local rparams = RaycastParams.new()
	rparams.FilterType = Enum.RaycastFilterType.Exclude
	rparams.FilterDescendantsInstances = {game.Players.LocalPlayer.Character}
	local ogpos = Camera.CFrame.Position
	local result = workspace:Raycast(workspace.CurrentCamera.CFrame.Position,Position.Unit.Direction*2000,rparams)
	warn("Local Script camera Position: "..tostring(workspace.CurrentCamera.CFrame.Position))

Did you mean Position.Direction.Unit * 2000?

1 Like

Have you tried using this method of the camera class?

ScreenPointToRay and ViewportPointToRay work the same, but ViewportPointToRay ignores Roblox Core GUI (which i need to)
Also i might have found the cause of the problem, the custom mobile shiftlock script gives camera offset of CFrame.new(-1.75,0,0), but then it then overrides by roblox MouseLockController core module.

I will have to either:
a) Find a way to give custom mobile shiftlock higher priority
b) Edit MouseLockController to be able support mobile

Though, I’m having a problem with b) because the core script is too complex for me

You can easily make a custom shift lock without using built in shiftlock with humanoid.CameraOffset property.

Well, i will use this as an alternative for now, thanks.

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