Advertisement
Anukun_Lucifer

EffectWalk

Oct 19th, 2024
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | Gaming | 0 0
  1. local Player = game:GetService("Players").LocalPlayer
  2. local Camera = workspace.CurrentCamera
  3. local UserInputService = game:GetService("UserInputService")
  4. local Humanoid = Player.Character:WaitForChild("Humanoid")
  5.  
  6. -- ตัวแปรสำหรับการประมวลผลการเคลื่อนไหว
  7. local int, int2, val, val2 = 5, 5, 0, 0
  8. local func1, func2, func3, func4 = 0, 0, 0, 0
  9.  
  10. -- ฟังก์ชัน lerp สำหรับการปรับค่าอย่างนุ่มนวล
  11. local function lerp(a, b, c)
  12.     return a + (b - a) * c
  13. end
  14.  
  15. -- อัปเดตกล้องและการเคลื่อนไหวในทุกเฟรม
  16. game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
  17.     -- ปรับ deltaTime ให้เหมาะสมกับการคำนวณ
  18.     deltaTime = deltaTime * 30
  19.  
  20.     -- หยุดการทำงานถ้าตัวละครตาย
  21.     if Humanoid.Health <= 0 then return end
  22.  
  23.     -- ดึงข้อมูลความเร็วของ RootPart และคำนวณขนาดเวกเตอร์ของการเคลื่อนไหว
  24.     local rootVel = Humanoid.RootPart and Humanoid.RootPart.Velocity or Vector3.new()
  25.     local rootMagnitude = Vector3.new(rootVel.X, 0, rootVel.Z).Magnitude
  26.  
  27.     -- คำนวณค่าการเคลื่อนไหวที่นุ่มนวลสำหรับการสั่นกล้อง
  28.     func1 = lerp(func1, math.cos(tick() * 0.5) * 0.05 * deltaTime, 0.05 * deltaTime)
  29.     func2 = lerp(func2, math.sin(tick() * 0.5) * 0.05 * deltaTime, 0.05 * deltaTime)
  30.  
  31.     -- อัปเดตตำแหน่งกล้องและการหมุน
  32.     Camera.CFrame = Camera.CFrame * CFrame.Angles(0, 0, math.rad(func3)) *
  33.         CFrame.fromEulerAnglesXYZ(math.rad(func4 * deltaTime), math.rad(val * deltaTime), val2)
  34.  
  35.     -- คำนวณการเคลื่อนไหวในแกน X ตามความเร็วของ RootPart
  36.     val2 = math.clamp(
  37.         lerp(val2, -Camera.CFrame:VectorToObjectSpace(rootVel / math.max(Humanoid.WalkSpeed, 0.01)).X * 0.04, 0.1 * deltaTime),
  38.         -0.12, 0.1
  39.     )
  40.  
  41.     -- ปรับค่า func3 และ func4 สำหรับการหมุนตามการเคลื่อนไหวของเมาส์
  42.     func3 = lerp(func3, math.clamp(UserInputService:GetMouseDelta().X, -2.5, 2.5), 0.25 * deltaTime)
  43.     func4 = lerp(func4, math.sin(tick() * int) / 5 * math.min(1, int2 / 10), 0.25 * deltaTime)
  44.  
  45.     -- ปรับค่า val สำหรับการเคลื่อนไหวเมื่อความเร็ว RootPart เกิน 1
  46.     val = rootMagnitude > 1 and lerp(val, math.cos(tick() * 0.5 * math.floor(int)) * (int / 200), 0.25 * deltaTime)
  47.         or lerp(val, 0, 0.05 * deltaTime)
  48.  
  49.     -- ปรับค่าตัวแปร int และ int2 ตามความเร็วของ RootPart
  50.     int, int2 = rootMagnitude > 6 and 10 or 6, rootMagnitude > 0.1 and 7 or 0
  51. end)
  52.  
Tags: Roblox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement