Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ตั้งค่าความเร็วเดินปกติและความเร็วเมื่อวิ่ง
- local NormalWalkSpeed = 8
- local SprintSpeed = 12
- local CameraEffect = true -- ตัวแปรควบคุมว่าเอฟเฟกต์กล้องจะถูกใช้งานหรือไม่
- -- เรียกใช้งาน ContextActionService เพื่อใช้ปุ่มในการควบคุม
- local cas = game:GetService("ContextActionService")
- local Leftc = Enum.KeyCode.LeftControl -- ปุ่มซ้ายควบคุมการวิ่ง
- local RightC = Enum.KeyCode.RightControl -- ปุ่มขวาควบคุมการวิ่ง
- local player = game:GetService("Players").LocalPlayer
- local char = player.Character or player.CharacterAdded:Wait()
- local Humanoid = char:WaitForChild("Humanoid") -- เรียกตัวละครผู้เล่น
- -- ตั้งค่ากล้องและเรียกใช้ TweenService เพื่อให้เกิดการเคลื่อนไหวกล้องแบบนุ่มนวล
- local Camera = game.Workspace.CurrentCamera
- local TweenService = game:GetService("TweenService")
- local UIS = game:GetService("UserInputService")
- -- ฟังก์ชันนี้จะทำงานเมื่อมีการกดปุ่ม LeftShift เพื่อเพิ่มความเร็ววิ่งและเปลี่ยน FieldOfView ของกล้อง
- UIS.InputBegan:Connect(function(key, gameProcessed)
- if gameProcessed then return end -- หยุดการทำงานถ้าเป็นอินพุตที่ถูกประมวลผลแล้ว
- if key.KeyCode == Enum.KeyCode.LeftShift then
- if CameraEffect == true then
- -- เพิ่ม FieldOfView ของกล้องเพื่อให้เกิดเอฟเฟกต์การวิ่ง
- TweenService:Create(Camera, TweenInfo.new(0.5), {FieldOfView = 80}):Play()
- end
- Humanoid.WalkSpeed = SprintSpeed -- ตั้งความเร็วการวิ่ง
- end
- end)
- -- ฟังก์ชันนี้จะทำงานเมื่อปล่อยปุ่ม LeftShift เพื่อลดความเร็วกลับไปที่ค่าเดินปกติและรีเซ็ต FieldOfView ของกล้อง
- UIS.InputEnded:Connect(function(key, gameProcessed)
- if gameProcessed then return end
- if key.KeyCode == Enum.KeyCode.LeftShift then
- if CameraEffect == true then
- -- ลด FieldOfView ของกล้องกลับไปที่ค่าเริ่มต้น
- TweenService:Create(Camera, TweenInfo.new(0.5), {FieldOfView = 70}):Play()
- end
- Humanoid.WalkSpeed = NormalWalkSpeed -- ตั้งความเร็วการเดินปกติ
- end
- end)
- --------------------------------------------------- ปุ่มวิ่งสำหรับมือถือ
- -- ฟังก์ชัน handleContext สำหรับการวิ่งในมือถือ เมื่อต้องการเริ่มหรือหยุดวิ่ง
- local function handleContext(name, state, input)
- if state == Enum.UserInputState.Begin then
- if CameraEffect == true then
- -- เพิ่ม FieldOfView ของกล้องเมื่อเริ่มวิ่ง
- TweenService:Create(Camera, TweenInfo.new(0.5), {FieldOfView = 80}):Play()
- end
- Humanoid.WalkSpeed = SprintSpeed -- เพิ่มความเร็วการวิ่ง
- else
- if CameraEffect == true then
- -- ลด FieldOfView ของกล้องเมื่อหยุดวิ่ง
- TweenService:Create(Camera, TweenInfo.new(0.5), {FieldOfView = 70}):Play()
- end
- Humanoid.WalkSpeed = NormalWalkSpeed -- ลดความเร็วกลับเป็นค่าเดินปกติ
- end
- end
- -- ผูกฟังก์ชันการวิ่งกับปุ่มควบคุม และตั้งค่าตำแหน่งและขนาดของปุ่มในอินเตอร์เฟส
- cas:BindAction("วิ่ง", handleContext, true, Leftc, RightC)
- cas:SetPosition("วิ่ง", UDim2.new(.2, 0, .5, 0)) -- กำหนดตำแหน่งปุ่ม
- cas:SetTitle("วิ่ง", "วิ่ง") -- ตั้งชื่อปุ่มให้แสดงว่า "วิ่ง"
- cas:GetButton("วิ่ง").Size = UDim2.new(.3, 0, .3, 0) -- กำหนดขนาดของปุ่ม
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement