so, i’m working with a game studio on my first commission, and i want to lock the camera in the middle of the screen, similar to shift lock, like in this video showing one of Roblox’s SMG models
as of right now the gun looks like this. its really not finished and is in an early state, but i want it to be similar to the smg models shown above
local script with main components
Script
-- Local Variables -- local plr = game.Players.LocalPlayer local mouse = plr:GetMouse() local camera = workspace.CurrentCamera -- Services -- local replicatedStorage = game:GetService("ReplicatedStorage") local ServerScriptService = game:GetService("ServerScriptService") local uis = game:GetService("UserInputService") local runService = game:GetService("RunService") local debrisService = game:GetService("Debris") -- Tool Values -- local tool = script.Parent -- Modules Scripts -- local weaponHandler = require(replicatedStorage:WaitForChild("WeaponHandler")) local settingsModule = require(tool:WaitForChild("Settings")) -- Character local char = plr.Character or plr.CharacterAdded:Wait() local hum = char:WaitForChild("Humanoid") -- GUI Variables -- local weaponGui = plr.PlayerGui:WaitForChild("WeaponGui") local ammoDisplay = weaponGui:WaitForChild("ammoDisplay") -- ====================================================== -- NON-EXISTING VARIABLES local holdingDownMouse = false local currentAmmo = settingsModule.ammoPerMag local outOfAmmo = false local onCooldown = false -- ====================================================== -- Functions -- local function updateGui(textInstance:TextLabel, value) textInstance.Text = value end local function changeMouseState(bool) if bool == false then uis.MouseBehavior = Enum.MouseBehavior.Default else uis.MouseBehavior = Enum.MouseBehavior.LockCenter end end tool.Equipped:Connect(function() weaponGui.Enabled = true updateGui(ammoDisplay, currentAmmo) hum.CameraOffset = Vector3.new(1.5,0,-1.5) -- new camera offset changeMouseState(true) end) tool.Unequipped:Connect(function() weaponGui.Enabled = false hum.CameraOffset = Vector3.new(0, 0, 0) -- new camera offset changeMouseState(false) end) mouse.Button1Down:Connect(function() holdingDownMouse = true runService.Heartbeat:Connect(function() -- automatic weapon fire loop if holdingDownMouse and not outOfAmmo and currentAmmo >= 1 and not onCooldown then onCooldown = true weaponHandler.FireBullet() -- Fires the weapon, server takes over from here currentAmmo = currentAmmo - 1 updateGui(ammoDisplay, currentAmmo) task.wait(settingsModule.fireRate) onCooldown = false end end) end) mouse.Button1Up:Connect(function() holdingDownMouse = false end)
if anyone has any thoughts pls let me know, thank you!