So I’ve got a basic over the shoulder script as shown below (it’s currently a local script in StarterCharacterScripts), but I can’t seem to find a way to make it work when a tool is equipped. If anyone has any solutions, it’d be much appreciated!
local uis = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
humanoid.AutoRotate = false
local hrp = char:WaitForChild("HumanoidRootPart")
local x = 0
local y = 0
local offset = Vector3.new(3, 3, 10)
uis.InputChanged:Connect(function(input, processed)
if processed then return end
if input.UserInputType == Enum.UserInputType.MouseMovement then
x = x - input.Delta.X
y = math.clamp(y - input.Delta.Y*0.4, -75, 75)
hrp.CFrame = hrp.CFrame * CFrame.Angles(0, math.rad(-input.Delta.X), 0)
end
end)
game:GetService("RunService").RenderStepped:Connect(function()
uis.MouseBehavior = Enum.MouseBehavior.LockCenter
local startCFrame = CFrame.new((hrp.CFrame.Position)) * CFrame.Angles(0, math.rad(x), 0) * CFrame.Angles(math.rad(y), 0, 0)
local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, offset.Z))
local cameraDirection = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, -10000))
camera.CFrame = CFrame.new(cameraCFrame.Position, cameraDirection.Position)
end)
Did you create a custom tool or use an existing tool? Many tools when equipped will change the camera type or create their own camera system which could overwrite yours. Having a tool equipped should not otherwise effect the camera.
Ah, sorry, I should have been more specific. When the tool is equipped, I want the cam to switch to over the shoulder. When it’s unequipped, it should return to normal.
Not exactly a solution to your problem but a question, can’t you just set the CFrame to be a left/right Arm/UpperArm and add a bit to the Y-value?
And then to make it straight just set the orientation to the hrp every renderstep?
Oh, in that case you want to create an Enable() and Disable() function
local uis = game:GetService("UserInputService")
local camera = workspace.CurrentCamera
local char = script.Parent
local humanoid = char:WaitForChild("Humanoid")
local hrp = char:WaitForChild("HumanoidRootPart")
local x = 0
local y = 0
local offset = Vector3.new(3, 3, 10)
local inputEvent
local renderSteppedEvent
function Enable()
camera.CameraType = Enum.CameraType.Scriptable
humanoid.AutoRotate = false
inputEvent = uis.InputChanged:Connect(function(input, processed)
if processed then return end
if input.UserInputType == Enum.UserInputType.MouseMovement then
x = x - input.Delta.X
y = math.clamp(y - input.Delta.Y*0.4, -75, 75)
hrp.CFrame = hrp.CFrame * CFrame.Angles(0, math.rad(-input.Delta.X), 0)
end
end)
renderSteppedEvent = game:GetService("RunService").RenderStepped:Connect(function()
uis.MouseBehavior = Enum.MouseBehavior.LockCenter
local startCFrame = CFrame.new((hrp.CFrame.Position)) * CFrame.Angles(0, math.rad(x), 0) * CFrame.Angles(math.rad(y), 0, 0)
local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, offset.Z))
local cameraDirection = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, -10000))
camera.CFrame = CFrame.new(cameraCFrame.Position, cameraDirection.Position)
end)
end
function Disable()
inputEvent:Disconnect()
renderSteppedEvent:Disconnect()
humanoid.AutoRotate = true
x = 0
y = 0
camera.CameraType = Enum.CameraType.Track
end
Now when you need to use the shoulder camera, just call Enable, and use Disable to stop it
char.ChildAdded:Connect(function(NewChild)
if NewChild:IsA("Tool") then
--a new tool is equipped
--NewChild is the tool equipped
Enable()
end
end)
--then to detect if the tool is unequipped you do the opposite
char.ChildRemoved:Connect(function(RemovedChild)
if RemovedChild:IsA("Tool") then
--the tool is unequipped
--RemovedChild is the tool unequipped
Disable()
end
end)