#Camera offset

1 messages · Page 1 of 1 (latest)

thick quest
#

I was trying to prevent from clipping through walls but after i added offset to my custom camera it made clipping again possible

local function UpdateCamera(Delta: number)
    if not Character then return end
    
    local Head: Part = Character:FindFirstChild("Head")
    local Root: Part = Character:FindFirstChild("HumanoidRootPart")
    if not (Head or Root) then return end
    
    local CameraRotation: CFrame = CFrame.Angles(0, math.rad(yaw), 0) * CFrame.Angles(math.rad(pitch), 0, 0)    
    Root.CFrame = CFrame.new(Root.Position) * CFrame.Angles(0, math.rad(yaw), 0)
    
    
    local BaseDistance = .5
    
    local RayOrigin = Head.CFrame.Position
    local RayDirection = (-CameraRotation.LookVector * BaseDistance)
    
    local Params = RaycastParams.new()
    Params.FilterDescendantsInstances = {Character}
    Params.FilterType = Enum.RaycastFilterType.Exclude
    
    
    local _results = workspace:Raycast(RayOrigin, RayDirection, Params)
    
    local Distance = BaseDistance
    if _results then
        Distance = math.max(.1, _results.Distance - .05)
    end
    
    local BasePos = Head.Position - CameraRotation.LookVector * Distance
    
    local Pos = BasePos
    + CameraRotation.RightVector * CameraOffset.X
    + Vector3.new(0, CameraOffset.Y, 0)
    - CameraRotation.LookVector * CameraOffset.Z
    
    local TargetCFrame = CFrame.lookAt(Pos, Head.Position + CameraRotation.LookVector * 100)
    Camera.CFrame = TargetCFrame
end
topaz relic
#

i have see this not recommend if anyone plan create a restraunts or obby