Over the shoulder cam, when tool is active

Been working on my game for a while, and recently got to the point where I’ve started making tools to be used in game. I’ve made the base for my gun, which right now, just plays an idle animation and sound when equipped, and stops the animation whilst playing a different sound on unequip.

I want the gun to enable an over the shoulder cam (basically, shift lock) whenever it’s equipped, and disable this cam on unequip. But I have no idea how exactly I should go about this.

Reading other forum posts wasn’t much help, since they where all either over the shoulder all the time, or outdated and overcomplicated to the point of it being unusable for me.

Any help with this is massively appreciated, thanks!

Here’s my gun’s code, if that helps at all:

local tool = script.Parent

local Equip = script.Equip -- Equip sound
local Holster = script.Holster -- Holster sound
local idle = script:FindFirstChild("Idle") -- Idle animation

local player = script.Parent.Parent.Parent
character = player.Character
if not character or not character.Parent then
	character = player.CharacterAdded:Wait()
end

local humanoid = character:WaitForChild("Humanoid")

tool.Equipped:Connect(function()
	
	Equip:Play()
	
	local idleAnimation = humanoid:LoadAnimation(idle)
	idleAnimation:Play()
	
	tool.Unequipped:Connect(function()
		Holster:Play()
		idleAnimation:Stop()
	end)
	
end)
2 Likes

So basically you’re trying to made a third person cam while holding the gun?

Yup! Third person, over the shoulder cam which locks the mouse to the center of the screen and moves the player with the mouse like shift-lock does.

What I’d personally do is every renderstepp offset the camera’s CFrame to where you want it do go, sorta like this example,

local RunService = game:GetService("RunService")
local cam = workspace.CurrentCamera
local player = game.Players.LocalPlayer
local thirdPersonCameraOffset = CFrame.new(your preference)

cam.CameraType = Enum.CameraType.Scriptable -- Default camera behaviour will be paused while in third person cam
player.CameraMode = Enum.CameraMode.LockFirstPerson --lock mouse to the center of the screen just like shift lock

RunService.RenderStepped:Connect(function()
     cam.CFrame = cam.CFrame * thirdPersonCameraOffset -- Offsets the camera CFrame to whatever offset you want
end)

Note that is pseudo code and it’s only meant for instructions.

1 Like