0_nilType
arghh.. -w-
arghh.. -w-
CameraScript
--!nonstrict

-- Services, Modules, Types

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local RunService = game:GetService('RunService')
local Players = game:GetService('Players')
local Workspace = game:GetService('Workspace')

-- Common Variables

--\\ LocalPlayer
local localPlayer = Players.LocalPlayer
local character = localPlayer.Character or localPlayer.CharacterAdded:Wait()

--\\ Character
local humanoid = character:FindFirstChildOfClass('Humanoid')
local rootPart = character:WaitForChild('HumanoidRootPart'):: BasePart

--\\ Instances
local camera = workspace.CurrentCamera:: Camera

--\\ Camera Bobble
local bobFrequency = 8
local bobAmplitude = .18
local lerpSpeed = 10

local bobTime = 0
local currentOffset = Vector3.zero

--\\ Camera FOV
local baseFov = 90
local maxFovIncrease = 15
local fovSpeedMultiplier = .2
local fovLerpSpeed = 8

--\\ Raycast Params
local rayParams = RaycastParams.new()
rayParams.FilterType = Enum.RaycastFilterType.Exclude
rayParams.FilterDescendantsInstances = {character}
rayParams.CollisionGroup = 'Character'
rayParams.RespectCanCollide = true
rayParams.IgnoreWater = true

-- Misc. Data

-- Functions, Tasks

local function checkZ(distance: number): boolean
local origin = rootPart.Position
local direction = rootPart.CFrame.LookVector * distance

local result = Workspace:Raycast(origin, direction, rayParams)
return result == nil
end

local function preRender(deltaTime: number): ()
if not humanoid then return end

--\\ Camera Bobble
local moveDirection = humanoid.MoveDirection
local speed = moveDirection.Magnitude

local zOffset = 0
if checkZ(1.2) then
zOffset = -1.2
end

if speed > 0 and humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then
bobTime += deltaTime * bobFrequency
local offset = Vector3.new(
math.sin(bobTime) * bobAmplitude,
.2 + math.abs(math.cos(bobTime)) * bobAmplitude,
zOffset
)
currentOffset = currentOffset:Lerp(offset, deltaTime * lerpSpeed)
else
currentOffset = currentOffset:Lerp(Vector3.new(0, .2, zOffset), deltaTime * lerpSpeed)
end

humanoid.CameraOffset = currentOffset

--\\ FOV Change
local velocity = rootPart.AssemblyLinearVelocity.Magnitude
local targetFov = baseFov + math.clamp(
velocity * fovSpeedMultiplier,
0,
maxFovIncrease
)

camera.FieldOfView = camera.FieldOfView + (targetFov - camera.FieldOfView) * deltaTime * fovLerpSpeed
end

-- Connections, Actions

camera.FieldOfView = baseFov
RunService.PreRender:Connect(preRender)
Comments
Джурик 7 Feb @ 10:30pm 
HOLD STEADY :PEAKpoint:
Po 7 Jan @ 12:46pm 
лучший korton из всех
Stormyfox 26 Dec, 2025 @ 4:44pm 
:3
0_nilType 6 Oct, 2025 @ 5:29am 
:3