local ShiftLockController = {}
-- Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local GameSettings = UserSettings().GameSettings
-- Constants
local CAMERA_OFFSET_ENABLED = Vector3.new(0, 1.7, 0)
local CAMERA_OFFSET_DISABLED = Vector3.new(0, 0, 0)
local TRANSITION_SPEED = 5
local Spring = require(script:WaitForChild("Spring"))
-- Variables
local Player = Players.LocalPlayer
ShiftLockController.IsEnabled = false
local currentCameraOffset = CAMERA_OFFSET_DISABLED
local function updateCameraOffset(dt) --Delta time
local character = Player.Character or Player.CharacterAdded:Wait()
local humanoid = character and character:FindFirstChildOfClass("Humanoid")
if humanoid then
-- Linearly interpolate the camera offset towards target
currentCameraOffset = currentCameraOffset:Lerp(
ShiftLockController.IsEnabled and CAMERA_OFFSET_ENABLED or CAMERA_OFFSET_DISABLED,
dt * TRANSITION_SPEED
)
humanoid.CameraOffset = currentCameraOffset
end
end
function ShiftLockController.Enable()
if not ShiftLockController.IsEnabled then
ShiftLockController.IsEnabled = true
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
GameSettings.RotationType = Enum.RotationType.CameraRelative
end
end
function ShiftLockController.Disable()
if ShiftLockController.IsEnabled then
ShiftLockController.IsEnabled = false
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
GameSettings.RotationType = Enum.RotationType.MovementRelative
end
end
--Loop to smoothly update camoffset
RunService.Heartbeat:Connect(function(dt)
updateCameraOffset(dt)
end)
return ShiftLockController
Would i have to be concerned about performance issues whilst using this heartbeat connection?And if so, which would be the best solution:
- Managing the connection with maid
- Using a coroutine for a smooth transition
- Using spring (I don’t really know how this module works, but I’ve heard about it)
- Other
Thx