Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Player = game:GetService("Players").LocalPlayer
- local Camera = workspace.CurrentCamera
- local UserInputService = game:GetService("UserInputService")
- local Humanoid = Player.Character:WaitForChild("Humanoid")
- -- ตัวแปรสำหรับการประมวลผลการเคลื่อนไหว
- local int, int2, val, val2 = 5, 5, 0, 0
- local func1, func2, func3, func4 = 0, 0, 0, 0
- -- ฟังก์ชัน lerp สำหรับการปรับค่าอย่างนุ่มนวล
- local function lerp(a, b, c)
- return a + (b - a) * c
- end
- -- อัปเดตกล้องและการเคลื่อนไหวในทุกเฟรม
- game:GetService("RunService").RenderStepped:Connect(function(deltaTime)
- -- ปรับ deltaTime ให้เหมาะสมกับการคำนวณ
- deltaTime = deltaTime * 30
- -- หยุดการทำงานถ้าตัวละครตาย
- if Humanoid.Health <= 0 then return end
- -- ดึงข้อมูลความเร็วของ RootPart และคำนวณขนาดเวกเตอร์ของการเคลื่อนไหว
- local rootVel = Humanoid.RootPart and Humanoid.RootPart.Velocity or Vector3.new()
- local rootMagnitude = Vector3.new(rootVel.X, 0, rootVel.Z).Magnitude
- -- คำนวณค่าการเคลื่อนไหวที่นุ่มนวลสำหรับการสั่นกล้อง
- func1 = lerp(func1, math.cos(tick() * 0.5) * 0.05 * deltaTime, 0.05 * deltaTime)
- func2 = lerp(func2, math.sin(tick() * 0.5) * 0.05 * deltaTime, 0.05 * deltaTime)
- -- อัปเดตตำแหน่งกล้องและการหมุน
- Camera.CFrame = Camera.CFrame * CFrame.Angles(0, 0, math.rad(func3)) *
- CFrame.fromEulerAnglesXYZ(math.rad(func4 * deltaTime), math.rad(val * deltaTime), val2)
- -- คำนวณการเคลื่อนไหวในแกน X ตามความเร็วของ RootPart
- val2 = math.clamp(
- lerp(val2, -Camera.CFrame:VectorToObjectSpace(rootVel / math.max(Humanoid.WalkSpeed, 0.01)).X * 0.04, 0.1 * deltaTime),
- -0.12, 0.1
- )
- -- ปรับค่า func3 และ func4 สำหรับการหมุนตามการเคลื่อนไหวของเมาส์
- func3 = lerp(func3, math.clamp(UserInputService:GetMouseDelta().X, -2.5, 2.5), 0.25 * deltaTime)
- func4 = lerp(func4, math.sin(tick() * int) / 5 * math.min(1, int2 / 10), 0.25 * deltaTime)
- -- ปรับค่า val สำหรับการเคลื่อนไหวเมื่อความเร็ว RootPart เกิน 1
- val = rootMagnitude > 1 and lerp(val, math.cos(tick() * 0.5 * math.floor(int)) * (int / 200), 0.25 * deltaTime)
- or lerp(val, 0, 0.05 * deltaTime)
- -- ปรับค่าตัวแปร int และ int2 ตามความเร็วของ RootPart
- int, int2 = rootMagnitude > 6 and 10 or 6, rootMagnitude > 0.1 and 7 or 0
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement