Advertisement
Dfgjfj

Dynamic Camera Offset script

Feb 9th, 2025
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. local RunService = game:GetService("RunService")
  2. local Players = game:GetService("Players")
  3. local LocalPlayer = Players.LocalPlayer
  4. local Char = LocalPlayer.Character
  5. local Humanoid = Char:WaitForChild("Humanoid")
  6. local HumanoidRootPart = Char:WaitForChild("HumanoidRootPart")
  7. local LastPosition = HumanoidRootPart.Position
  8. local IntensityX = 0.8
  9. local IntensityY = 1.15
  10. local Smoothness = 0.10
  11. RunService.Heartbeat:Connect(function(FrameTime)
  12.     local CurrentTime = workspace:GetServerTimeNow()
  13.     local CurrentPosition = HumanoidRootPart.Position
  14.     local CurrentDistance = (CurrentPosition - LastPosition).Magnitude
  15.    
  16.     if Humanoid.MoveDirection.Magnitude > 0 then
  17.         local CurrentSpeed = math.floor(CurrentDistance / FrameTime) * 10^-2
  18.        
  19.         local X = math.cos(CurrentTime * CurrentSpeed) * IntensityX
  20.         local Y = math.abs(math.sin(CurrentTime * CurrentSpeed )) * IntensityY
  21.         Humanoid.CameraOffset = Humanoid.CameraOffset:Lerp(Vector3.new(X,Y,0),Smoothness)
  22.         LastPosition = CurrentPosition
  23.     else
  24.         Humanoid.CameraOffset = Humanoid.CameraOffset *  (1 - Smoothness)
  25.     end
  26. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement