學習
引擎類別
HapticService
已棄用
無法建立
服務
未複製

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡


概要

繼承成員

API 參考
方法
GetMotor
功能: Input
HapticService:GetMotor(
inputType:Enum.UserInputType, vibrationMotor:Enum.VibrationMotor
參數
vibrationMotor:Enum.VibrationMotor
返回

IsMotorSupported
功能: Input
HapticService:IsMotorSupported(
inputType:Enum.UserInputType, vibrationMotor:Enum.VibrationMotor
參數
vibrationMotor:Enum.VibrationMotor
返回

IsVibrationSupported
功能: Input
HapticService:IsVibrationSupported(inputType:Enum.UserInputType):boolean
參數
返回

SetMotor
功能: Input
HapticService:SetMotor(
inputType:Enum.UserInputType, vibrationMotor:Enum.VibrationMotor, vibrationValues:Tuple
):()
參數
vibrationMotor:Enum.VibrationMotor
vibrationValues:Tuple
返回
()
範例程式碼
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 onInputChanged(property)
if property == "Position" then
HapticService:SetMotor(inputType, vibrationMotor, input.Position.Z)
end
end
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(onInputChanged)
end
end
end
end
UserInputService.InputBegan:Connect(onInputBegan)

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。