I’m currently creating a shoulder camera right now and so far I think I’m doing pretty good. The only problem I’m having is I don’t know how I could make the camera rotatable whilst the camera is Scriptable.
I have already tried doing mouse positions but that just makes the camera go out of control or just not work at all.
My script is located in StarterGui as a LocalScript
local cam = game.Workspace.CurrentCamera
cam.FieldOfView = 100
local rs = game:GetService("RunService")
rs.RenderStepped:Connect(function(deltaTime)
if cam.CameraType ~= Enum.CameraType.Scriptable then
cam.CameraType = Enum.CameraType.Scriptable
end
local chr = game.Players.LocalPlayer.Character
local torso = chr:WaitForChild("Torso")
local posOff = Vector3.new(2.3, 2.35, 3.5)
local newPos = CFrame.new(torso.CFrame.p) + posOff
cam.CFrame = cam.CFrame:Lerp(newPos * cam.CFrame.Rotation, 0.1)
end)
You’ll have to build the camera CFrame out of two parts, the Position, which I assume is the part you want scripted, and the rotation provided by the player. Since you want a shoulder camera you’ll also have the offset be separate: cameraCFrame = CFrame.new(scriptedPosition) * rotationCFrame * CFrame.new(positionOffset)
rotationCFrame would then be a CFrame with only rotation, calculated from a yaw and pitch which is in turn controlled by the player.
Hello, I think your code needs a little modification. Please understand that this code is not debugged or optimized.I think this is what you want to do:
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local cam = game.Workspace.CurrentCamera
cam.FieldOfView = 100
cam.CameraType = Enum.CameraType.Scriptable
local cameraRotation = Vector2.new()
local rotationSpeed = Vector2.new(0.5, 0.5)
UserInputService.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
cameraRotation = cameraRotation + Vector2.new(input.Delta.x, input.Delta.y) * rotationSpeed
end
end)
RunService.RenderStepped:Connect(function(deltaTime)
local character = player.Character
if character then
local torso = character:WaitForChild("Torso")
local yOffset = 2.35
local distance = 3.5
local horizontalAngle = math.rad(cameraRotation.x)
local verticalAngle = math.rad(cameraRotation.y)
local x = distance * math.cos(verticalAngle) * math.sin(horizontalAngle)
local y = distance * math.sin(verticalAngle) + yOffset
local z = distance * math.cos(verticalAngle) * math.cos(horizontalAngle)
local cameraPosition = torso.CFrame.p + Vector3.new(x, y, z)
cam.CFrame = CFrame.new(cameraPosition, torso.CFrame.p + Vector3.new(0, yOffset, 0))
end
end)