Hello, is there a way i can make it where the player cant turn there camera at all?
Probaly will need to script it.
I would suggest creating a Custom Camera instead of modifying the Camera to disable turning around.
I took advice from an old scripting helpers post here, made some modifications to match your use case:
--LocalScript inside StarterCharacterScripts
local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local character = script.Parent
local head = character:WaitForChild("Head", 5)
--converts degrees to rads, useful for CFrame.Angles
local r = math.rad
--camera fixed rotation and offset
local rotation = CFrame.Angles(r(0), r(-60), r(0))
local offset = CFrame.new(12, 20, 0)
camera.CameraType = Enum.CameraType.Scriptable
local position = head.Position
RunService.RenderStepped:Connect(function()
if character and position then
position = head.Position
-- Rotate CFrame by rotation value
local startCFrame = CFrame.new(position)*rotation
--Offset CFrame by defined offset
local cameraPos = startCFrame:ToWorldSpace(offset).Position
--Set camera properties
camera.CFrame = CFrame.new(cameraPos, position)
camera.Focus = CFrame.new(position)
camera.CameraSubject = head
end
end)
im a little confused, where would i put this in my script?
current script
local Attachment = game.Workspace.ToolAttachments.Bed
local Humanoid = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local PlayerModule = require(game.Players.LocalPlayer.PlayerScripts:WaitForChild("PlayerModule"))
local Controls = PlayerModule:GetControls()
local CurrentCam = game.Workspace.CurrentCamera
game.ReplicatedStorage.PickUpTools.Tool1.OnClientEvent:Connect(function()
Humanoid:MoveTo(Attachment.WorldPosition)
CurrentCam.CameraType = Enum.CameraType.Custom
Controls:Disable()
Humanoid.WalkSpeed = 7
local connection
connection = Humanoid.MoveToFinished:Connect(function()
wait(2)
Controls:Enable()
Humanoid.WalkSpeed = 16
end)
end)
It’s an entire script by itself, simply create a LocalScript
in PlayerScripts.StarterCharacterScripts
and paste the code in(also temporary disable your own to test it).
Sorry for reviving an old post but I just want to say that you don’t need the rotation aspect because the camera automatically rotates when you set its subject. I really like your code and just slightly modified it here:
local camera = workspace.CurrentCamera
local head = script.Parent:WaitForChild("Head")
local cameraOffset = Vector3.new(-10, 20, 0)
game:GetService("RunService").RenderStepped:Connect(function()
local headPosition = head.Position
local cameraPositionCFrame = CFrame.new(headPosition) + cameraOffset
camera.CFrame = CFrame.new(cameraPositionCFrame.Position, headPosition)
camera.Focus = CFrame.new(headPosition)
camera.CameraSubject = head
end)
You can edit the offset however you like. There’s no need for a rotation as it will get overwritten anyways. To prove this to yourself you can run the same code but modify the camera.CFrame with a given rotation (example below)
local camera = workspace.CurrentCamera
local head = script.Parent:WaitForChild("Head")
local cameraOffset = Vector3.new(-10, 20, 0)
local cameraRotation = CFrame.Angles(0, math.rad(-60), 0)
game:GetService("RunService").RenderStepped:Connect(function()
local headPosition = head.Position
local cameraPositionCFrame = (CFrame.new(headPosition) + cameraOffset) * cameraRotation
camera.CFrame = CFrame.new(cameraPositionCFrame.Position, headPosition)
camera.Focus = CFrame.new(headPosition)
camera.CameraSubject = head
end)
This code block gives you the exact same result as the first code block.