Haptic Service
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
ข้อมูลสรุป
วิธีการ
GetMotor(inputType: Enum.UserInputType,vibrationMotor: Enum.VibrationMotor):Tuple |
IsMotorSupported(inputType: Enum.UserInputType,vibrationMotor: Enum.VibrationMotor):boolean |
IsVibrationSupported(inputType: Enum.UserInputType):boolean |
SetMotor(inputType: Enum.UserInputType,vibrationMotor: Enum.VibrationMotor,vibrationValues: Tuple):() |
เอกสารอ้างอิงเกี่ยวกับ API
วิธีการ
Get Motor
พารามิเตอร์
ส่งค่ากลับ
Is Motor Supported
Haptic Service: Is Motor Supported(
พารามิเตอร์
ส่งค่ากลับ
Is Vibration Supported
พารามิเตอร์
ส่งค่ากลับ
Set Motor
Haptic Service: Set Motor(
):()
พารามิเตอร์
ส่งค่ากลับ
()
ตัวอย่างโค้ด
HapticService:SetMotor()
local UserInputService = game:GetService("UserInputService")
local HapticService = game:GetService("HapticService")
local cachedInputs = {}
local keyToVibration = {
[Enum.KeyCode.ButtonL2] = Enum.VibrationMotor.Small,
[Enum.KeyCode.ButtonR2] = Enum.VibrationMotor.Large,
}
local function onInputBegan(input)
if not cachedInputs[input] then
local inputType = input.UserInputType
if inputType.Name:find("Gamepad") then
local vibrationMotor = keyToVibration[input.KeyCode]
if vibrationMotor then
-- ติดตามการป้อนข้อมูลนี้ด้วยตนเองเพื่ออัปเดตมอเตอร์สั่นสะเทือนอย่างแม่นยำ
cachedInputs[input] = input.Changed:Connect(function(property)
if property == "Position" then
HapticService:SetMotor(inputType, vibrationMotor, input.Position.Z)
end
end)
end
end
end
end
UserInputService.InputBegan:Connect(onInputBegan)