-
What do you want to achieve? I want to restrict the camera’s rotation so players can’t see beyond their shoulders, with minimal errors. I mean the area behind the player’s back. Players should only be able to rotate until they reach the shoulders.
-
What is the issue? Somehow, the camera only faces the exact side when sitting on a different chair positioned opposite.
robloxapp-20250101-1549223.wmv (2.6 MB) -
What solutions have you tried so far? Yes, I tried to find one similar to my situation, but there is none.
if subject.Sit then
local cf = camera.CFrame
local headPos, shoulderPos = self:GetSubjectPosition(subject)
if headPos and shoulderPos then
local toHead = (headPos - cf.Position).unit
local toShoulder = (shoulderPos - cf.Position).unit
local horizontalLookVector = Vector3.new(toHead.X, 0, toHead.Z).unit
local horizontalShoulderVector = Vector3.new(toShoulder.X, 0, toShoulder.Z).unit
local angle = math.deg(math.acos(horizontalLookVector:Dot(horizontalShoulderVector)))
if angle > 90 then
local directionToShoulder = (shoulderPos - cf.Position).unit
local clampedYaw = Vector3.new(directionToShoulder.X, 0, directionToShoulder.Z).unit
local stayLook = cf.Position + clampedYaw * (headPos - shoulderPos).Magnitude
local stayCframe = CFrame.new(cf.Position, stayLook)
local tweenInfo = TweenInfo.new(0.3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
local tween = TweenService:Create(camera, tweenInfo, {CFrame = stayCframe})
tween:Play()
end
end
end