Skip to content
This repository was archived by the owner on Jun 11, 2020. It is now read-only.

Commit 1773d42

Browse files
committed
DE12842: Fix zooming while panning.
1 parent 5e9784d commit 1773d42

File tree

3 files changed

+33
-38
lines changed

3 files changed

+33
-38
lines changed

PlayerScripts/PlayerScriptsPlace/StarterPlayer/StarterPlayerScripts/CameraScript/RootCamera.rbxmx

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ local function CreateCamera()
8080
this.Enabled = false
8181
local pinchZoomSpeed = 20
8282
local isFirstPerson = false
83+
local isRightMouseDown = false
8384
this.RotateInput = Vector2.new()
8485

8586
function this:GetShiftLock()
@@ -197,13 +198,21 @@ local function CreateCamera()
197198
return isFirstPerson
198199
end
199200

201+
-- there are several cases to consider based on the state of input and camera rotation mode
200202
function this:UpdateMouseBehavior()
201-
if self:IsInFirstPerson() then
202-
pcall(function() GameSettings.RotationType = Enum.RotationType.CameraRelative end)
203-
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
204-
elseif not self:GetShiftLock() then
203+
-- first time transition to first person mode or shiftlock
204+
if isFirstPerson or self:GetShiftLock() then
205+
if UserInputService.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
206+
pcall(function() GameSettings.RotationType = Enum.RotationType.CameraRelative end)
207+
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
208+
end
209+
else
205210
pcall(function() GameSettings.RotationType = Enum.RotationType.MovementRelative end)
206-
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
211+
if isRightMouseDown then
212+
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
213+
else
214+
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
215+
end
207216
end
208217
end
209218

@@ -365,22 +374,17 @@ local function CreateCamera()
365374

366375
local function OnMouse2Down(input, processed)
367376
if processed then return end
368-
-- Check if they are in first-person
369-
if UserInputService.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
370-
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
371-
end
377+
isRightMouseDown = true
378+
this:UpdateMouseBehavior()
372379
panBeginLook = this:GetCameraLook()
373380
startPos = input.Position
374381
lastPos = startPos
375382
this.UserPanningTheCamera = true
376383
end
377384

378385
local function OnMouse2Up(input, processed)
379-
-- Check if they are in first-person
380-
if UserInputService.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
381-
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
382-
end
383-
386+
isRightMouseDown = false
387+
this:UpdateMouseBehavior()
384388
panBeginLook = nil
385389
startPos = nil
386390
lastPos = nil
@@ -565,7 +569,7 @@ local function CreateCamera()
565569
return Vector2.new(0,0)
566570
end
567571

568-
local InputBeganConn, InputChangedConn, InputEndedConn = nil, nil, nil
572+
local InputBeganConn, InputChangedConn, InputEndedConn, ShiftLockToggleConn = nil, nil, nil, nil
569573

570574
function this:DisconnectInputEvents()
571575
if InputBeganConn then
@@ -580,6 +584,10 @@ local function CreateCamera()
580584
InputEndedConn:disconnect()
581585
InputEndedConn = nil
582586
end
587+
if ShiftLockToggleConn then
588+
ShiftLockToggleConn:disconnect()
589+
ShiftLockToggleConn = nil
590+
end
583591
this.TurningLeft = false
584592
this.TurningRight = false
585593
this.LastCameraTransform = nil
@@ -639,6 +647,10 @@ local function CreateCamera()
639647
OnKeyUp(input, processed)
640648
end
641649
end)
650+
651+
ShiftLockToggleConn = ShiftLockController.OnShiftLockToggled.Event:connect(function()
652+
this:UpdateMouseBehavior()
653+
end)
642654

643655
this.RotateInput = Vector2.new()
644656

PlayerScripts/PlayerScriptsPlace/StarterPlayer/StarterPlayerScripts/CameraScript/ShiftLockController.rbxmx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ local IsShiftLocked = false
4242
local IsActionBound = false
4343
local IsInFirstPerson = false
4444

45+
-- Toggle Event
46+
ShiftLockController.OnShiftLockToggled = Instance.new('BindableEvent')
47+
4548
-- wrapping long conditional in function
4649
local function isShiftLockMode()
4750
return LocalPlayer.DevEnableMouseLock and GameSettings.ControlMode == Enum.ControlMode.MouseLockSwitch and
@@ -65,20 +68,11 @@ local function onShiftLockToggled()
6568
if IsShiftLocked then
6669
ShiftLockIcon.Image = SHIFT_LOCK_ON
6770
Mouse.Icon = SHIFT_LOCK_CURSOR
68-
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
69-
pcall(function()
70-
GameSettings.RotationType = Enum.RotationType.CameraRelative
71-
end)
7271
else
7372
ShiftLockIcon.Image = SHIFT_LOCK_OFF
7473
Mouse.Icon = ""
75-
if not IsInFirstPerson then
76-
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
77-
pcall(function()
78-
GameSettings.RotationType = Enum.RotationType.MovementRelative
79-
end)
80-
end
8174
end
75+
ShiftLockController.OnShiftLockToggled:Fire()
8276
end
8377

8478
local function initialize()
@@ -121,7 +115,6 @@ end
121115

122116
--[[ Input/Settings Changed Events ]]--
123117
local mouseLockSwitchFunc = function(actionName, inputState, inputObject)
124-
125118
if IsShiftLockMode then
126119
onShiftLockToggled()
127120
end
@@ -130,15 +123,13 @@ end
130123
local function disableShiftLock()
131124
if ShiftLockIcon then ShiftLockIcon.Visible = false end
132125
IsShiftLockMode = false
133-
if not IsInFirstPerson then
134-
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
135-
end
136126
Mouse.Icon = ""
137127
if InputCn then
138128
InputCn:disconnect()
139129
InputCn = nil
140130
end
141131
IsActionBound = false
132+
ShiftLockController.OnShiftLockToggled:Fire()
142133
end
143134

144135
-- TODO: Remove when we figure out ContextActionService without sinking keys
@@ -159,7 +150,7 @@ local function enableShiftLock()
159150
end
160151
if IsShiftLocked then
161152
Mouse.Icon = SHIFT_LOCK_CURSOR
162-
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
153+
ShiftLockController.OnShiftLockToggled:Fire()
163154
end
164155
if not IsActionBound then
165156
InputCn = UserInputService.InputBegan:connect(onShiftInputBegan)

PlayerScripts/PlayerScriptsPlace/StarterPlayer/StarterPlayerScripts/ControlScript/MasterControl/KeyboardMovement.rbxmx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ function KeyboardMovement:Enable()
6868
MasterControl:AddToPlayerMovement(currentMoveVector)
6969
end
7070

71-
local function isFirstPersonOrShiftLocked()
72-
-- Mouse behavior is being set by the camera script. So be warned that if you
73-
-- modify that script or implement a new camera, this may not work.
74-
if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter then
75-
return true
76-
end
77-
end
78-
7971
local moveForwardFunc = function(actionName, inputState, inputObject)
8072
if inputState == Enum.UserInputState.Begin then
8173
forwardValue = -1

0 commit comments

Comments
 (0)