#limiting camera movement relative to humanoid root part

1 messages · Page 1 of 1 (latest)

worn moss
#

for the free look system

#

ill probaly have to use :ToObjectSpace() on the humanoidrootpart

#

basically i want the camera to rotate a maximum of 90 degrees left or right

#
    local _,OldY:number,_ = CurrentCamera.CFrame:ToEulerAnglesXYZ()
    local function LimitCamera()
        
    local X:number,Y:number,Z:number = CurrentCamera.CFrame:ToEulerAnglesXYZ()
    local YLimit:number = clamp(Y,OldY-pi*.5,OldY+pi*.5)
    CurrentCamera.CFrame = CFrameNew(CurrentCamera.CFrame.Position)*CFrameAngles(X,YLimit,Z)
            
end

RunService:BindToRenderStep('LimitCamera',Enum.RenderPriority.Camera.Value,LimitCamera)
#

this is how i have it set up right now

#

but it only limits the camera properly if i have my humanoid root part rotated 90 degrees to the left/right

steel basin
#

Math.clamp

worn moss
#

thats what im doing

worn moss
#

@languid maple could i get some help with this

#

if you arent busy

languid maple
#

You need to store the root Y orientation when free looking mode is engaged, and clamp it between the offsets relative to that and -90 / +90

#

or maybe -45 / +45 depending on how wide you want the cone of vision to be

#

looks proper to me

#

💯

worn moss
#

i found a different way of doing this but it doesnt work fully

#
local function FreeLook(_,InputState:any,_)
    
    local IsKeyDown:boolean
    
    IsKeyDown = InputState == Enum.UserInputState.Begin

    if IsKeyDown and PlayerState:IsFirstPerson() then
        
        CharacterRotateEnabled = false
        Humanoid.AutoRotate = false
        
        local function LimitCamera()
        
            CurrentCamera.CFrame = Head.CFrame*CFrameFromAxisAngle(Mouse.Hit.LookVector*Head.Position,.5)
            
        end
        
        RunService:BindToRenderStep('LimitCamera',Enum.RenderPriority.Camera.Value,LimitCamera)
        
    else
        
        RunService:UnbindFromRenderStep('LimitCamera')
        CharacterRotateEnabled = true
        Humanoid.AutoRotate = true
        
    end
end

ContextActionService:BindAction("OnFreeLook",FreeLook,true,Enum.KeyCode.LeftAlt)