Untitled conversation
- User
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local CurrentCamera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local mouseLockLabel = script.Parent
local mouseLock = nil
local SHIFT_LOCK_OFF = 'rbxasset://textures/ui/mouseLock_off.png'
local SHIFT_LOCK_ON = 'rbxasset://textures/ui/mouseLock_on.png'
local SHIFT_LOCK_CURSOR = 'rbxasset://textures/MouseLockedCursor.png'
local MaxLength = 900000
local EnabledOffset = CFrame.new(1.7, 0, 0)
local DisabledOffset = CFrame.new(-1.7, 0, 0)
local function shiftLock(active)
local Character = Player.Character
if not Character or not Character:FindFirstChild("Humanoid") then return end
local hum = Character.Humanoid
local root = hum.RootPart
if active then
hum.CameraOffset = Vector3.new(1.75, 0, 0)
hum.AutoRotate = false
RunService:BindToRenderStep("ShiftLock", Enum.RenderPriority.Character.Value, function()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local _, y = CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ()
root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0, y, 0)
end)
Mouse.Icon = SHIFT_LOCK_CURSOR
mouseLockLabel.Image = SHIFT_LOCK_ON
else
hum.CameraOffset = Vector3.new(0, 0, 0)
RunService:UnbindFromRenderStep("ShiftLock")
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
hum.AutoRotate = true
Mouse.Icon = "http://www.roblox.com/asset/?id=7025168168"
mouseLockLabel.Image = SHIFT_LOCK_OFF
end
end
local function shiftLockSwitcher()
if mouseLock then
mouseLock:Disconnect()
mouseLock = nil
shiftLock(false)
CurrentCamera.CFrame = CurrentCamera.CFrame * DisabledOffset
else
mouseLock = RunService.Heartbeat:Connect(function()
local Character = Player.Character
if Character and Character:FindFirstChild("Humanoid") and Character:FindFirstChild("HumanoidRootPart") then
local hum = Character.Humanoid
local root = Character.HumanoidRootPart
hum.AutoRotate = false
root.CFrame = CFrame.new(
root.Position,
Vector3.new(
CurrentCamera.CFrame.LookVector.X * MaxLength,
root.Position.Y,
CurrentCamera.CFrame.LookVector.Z * MaxLength
)
)
CurrentCamera.CFrame = CurrentCamera.CFrame * EnabledOffset
CurrentCamera.Focus = CFrame.fromMatrix(
CurrentCamera.Focus.Position,
CurrentCamera.CFrame.RightVector,
CurrentCamera.CFrame.UpVector
) * EnabledOffset
end
end)
shiftLock(true)
end
end
mouseLockLabel.MouseButton1Click:Connect(shiftLockSwitcher)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
shiftLockSwitcher()
end
end)
hello. whenever shift lock is enabled, and player goes inside of first person (by zooming in), the camera still stays in the moved position, when instead, it should be like shiftlock isn't enabled. can you fix that?
To address the issue where the camera remains in the shifted position even when entering first-person mode, we need to ensure that the camera's behavior resets appropriately when transitioning between first-person and third-person views. This involves detecting when the player enters or exits first-person mode and adjusting the camera's CFrame and Focus accordingly.
Here’s how we can modify the script to handle this:
Current Behavior:
CFrame is offset using EnabledOffset.Desired Behavior:
Solution Approach:
FieldOfView or CameraType.CFrame and Focus dynamically based on whether the player is in first-person or third-person mode.Below is the modified version of your script with the necessary changes:
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local CurrentCamera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local Mouse = Player:GetMouse()
local mouseLockLabel = script.Parent
local mouseLock = nil
local SHIFT_LOCK_OFF = 'rbxasset://textures/ui/mouseLock_off.png'
local SHIFT_LOCK_ON = 'rbxasset://textures/ui/mouseLock_on.png'
local SHIFT_LOCK_CURSOR = 'rbxasset://textures/MouseLockedCursor.png'
local MaxLength = 900000
local EnabledOffset = CFrame.new(1.7, 0, 0)
local DisabledOffset = CFrame.new(-1.7, 0, 0)
-- Function to check if the camera is in first-person mode
local function isInFirstPerson()
local fov = CurrentCamera.FieldOfView
return fov >= 70 -- Adjust this threshold based on your game's first-person FOV
end
local function shiftLock(active)
local Character = Player.Character
if not Character or not Character:FindFirstChild("Humanoid") then return end
local hum = Character.Humanoid
local root = hum.RootPart
if active then
hum.CameraOffset = Vector3.new(1.75, 0, 0)
hum.AutoRotate = false
RunService:BindToRenderStep("ShiftLock", Enum.RenderPriority.Character.Value, function()
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
local _, y = CurrentCamera.CFrame.Rotation:ToEulerAnglesYXZ()
root.CFrame = CFrame.new(root.Position) * CFrame.Angles(0, y, 0)
-- Check if in first-person mode
if isInFirstPerson() then
CurrentCamera.CFrame = CFrame.new(CurrentCamera.CFrame.Position, root.Position)
CurrentCamera.Focus = CFrame.new(root.Position)
else
CurrentCamera.CFrame = CurrentCamera.CFrame * EnabledOffset
CurrentCamera.Focus = CFrame.fromMatrix(
CurrentCamera.Focus.Position,
CurrentCamera.CFrame.RightVector,
CurrentCamera.CFrame.UpVector
) * EnabledOffset
end
end)
Mouse.Icon = SHIFT_LOCK_CURSOR
mouseLockLabel.Image = SHIFT_LOCK_ON
else
hum.CameraOffset = Vector3.new(0, 0, 0)
RunService:UnbindFromRenderStep("ShiftLock")
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
hum.AutoRotate = true
Mouse.Icon = "http://www.roblox.com/asset/?id=7025168168"
mouseLockLabel.Image = SHIFT_LOCK_OFF
end
end
local function shiftLockSwitcher()
if mouseLock then
mouseLock:Disconnect()
mouseLock = nil
shiftLock(false)
CurrentCamera.CFrame = CurrentCamera.CFrame * DisabledOffset
else
mouseLock = RunService.Heartbeat:Connect(function()
local Character = Player.Character
if Character and Character:FindFirstChild("Humanoid") and Character:FindFirstChild("HumanoidRootPart") then
local hum = Character.Humanoid
local root = Character.HumanoidRootPart
hum.AutoRotate = false
root.CFrame = CFrame.new(
root.Position,
Vector3.new(
CurrentCamera.CFrame.LookVector.X * MaxLength,
root.Position.Y,
CurrentCamera.CFrame.LookVector.Z * MaxLength
)
)
-- Check if in first-person mode
if isInFirstPerson() then
CurrentCamera.CFrame = CFrame.new(CurrentCamera.CFrame.Position, root.Position)
CurrentCamera.Focus = CFrame.new(root.Position)
else
CurrentCamera.CFrame = CurrentCamera.CFrame * EnabledOffset
CurrentCamera.Focus = CFrame.fromMatrix(
CurrentCamera.Focus.Position,
CurrentCamera.CFrame.RightVector,
CurrentCamera.CFrame.UpVector
) * EnabledOffset
end
end
end)
shiftLock(true)
end
end
mouseLockLabel.MouseButton1Click:Connect(shiftLockSwitcher)
UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.LeftShift then
shiftLockSwitcher()
end
end)
First-Person Detection:
isInFirstPerson() to determine if the camera is in first-person mode based on its FieldOfView. You may need to adjust the threshold (fov >= 70) depending on your game's specific setup.Dynamic Camera Adjustment:
RunService:BindToRenderStep loop, the script now checks if the player is in first-person mode.CFrame and Focus are reset to their default positions relative to the character.EnabledOffset) is applied.Consistency Across Modes:
shiftLock function and the shiftLockSwitcher function to ensure consistent behavior.This solution ensures that the camera behaves naturally in first-person mode while maintaining the desired shift lock functionality in third-person mode.