Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to Unlock Cursor After Camera Manipulation?

Asked by 4 years ago

So, long story short, I have a script that manipulates each player's camera when they first spawn into my game; however, something about this makes it impossible for the user to move their cursor around (rather, it's just stuck in the middle of the screen, similarly to when you are in first person). Is there a way to fix this issue while still locking the player's camera angle to a specific spot?

Here is some of my code to show what exactly I do.

local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
game.Workspace.CurrentCamera.CameraType = "Fixed"
player.CameraMaxZoomDistance = 0 -- This may be causing the issue.
player.PlayerGui.EntranceGUI.Title.Visible = true

function onClicked(GUI)
    local window = player.PlayerGui.EntranceGUI
    window:remove() -- Removes the starting GUI
    game.Workspace.CurrentCamera.CameraSubject = player.Character.Humanoid
    game.Workspace.CurrentCamera.CameraType = "Custom"
    player.CameraMaxZoomDistance = 100
    game.Workspace.IntroMusic:Stop()
end
player.PlayerGui.EntranceGUI.Resume.ResumeImage.MouseButton1Click:connect(onClicked)

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

If i'm getting this correctly, when a player joins you change their camera to be static, then when they click a button things go back to normal.

Instead of using the cameratype Fixed (which in this case wasnt setting it correctly since the camera didnt load yet) let's use scriptable so that we can place the camera somewhere and ignore the whole mouse locked problem since the CameraScript lets go of controlling the camera with it set like this.

Also since the camera was not 'scriptable' and and the max zoom was set to 0, yes the mouse would get stuck in the middle.

local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer

-- it will not continue until the cameratype is scriptable, which lets us know the camera was loaded in
repeat wait() game.Workspace.CurrentCamera.CameraType="Scriptable" 
until game.Workspace.CurrentCamera.CameraType==Enum.CameraType.Scriptable
--you can change where the camera stay using cframe
game.Workspace.CurrentCamera.CFrame=CFrame.new(0,10,0)*CFrame.Angles(0,math.pi/6,0) 
player.PlayerGui.EntranceGUI.Title.Visible = true

function onClicked(GUI)
    local window = player.PlayerGui.EntranceGUI
    window:remove() -- Removes the starting GUI
    game.Workspace.CurrentCamera.CameraSubject = player.Character.Humanoid
    game.Workspace.CurrentCamera.CameraType = "Custom"
    game.Workspace.IntroMusic:Stop()
end
player.PlayerGui.EntranceGUI.Resume.ResumeImage.MouseButton1Click:connect(onClicked)
0
Thanks so much! Is there a way to make the camera focus on a particular object while in "Scriptable" mode? corncob567 275 — 4y
0
@corncob567 You could change the camera's cframe using CFrame.new(position,focus) both of which being vector3s DanzLua 2879 — 4y
Ad

Answer this question