HapticService

顯示已棄用項目

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

無法建立
服務
未複製

概要

方法

屬性

方法

GetMotor

將目前的振動值設為指定的 UserInputTypeEnum.VibrationMotor 。如果 SetMotor() 先前未被呼叫,此方法將無法返回任何東西。

參數

指定的 Enum.UserInputType

預設值:""
vibrationMotor: Enum.VibrationMotor

指定的 Enum.VibrationMotor

預設值:""

返回

目前的振動值設為指定的 Enum.UserInputTypeEnum.VibrationMotornil 如果 SetMotor() 尚未被呼叫。

IsMotorSupported

返回 true 如果指定的馬達可以與指定的 Enum.UserInputType 一起使用。

參數

正在檢查特定的 Enum.UserInputType 以獲得 Enum.VibrationMotor 協助持。

預設值:""
vibrationMotor: Enum.VibrationMotor

指定的 Enum.VibrationMotor 檢查是否支持指定的 Enum.UserInputType

預設值:""

返回

如果指定的馬達可以與指定的 Enum.UserInputType 一起使用,則 true ;否則,則 false

IsVibrationSupported

如果指定的 Enum.UserInputType 支持震動回饋,返回 true

參數

指定的 Enum.UserInputType 檢查是否支持醫療回饋。

預設值:""

返回

如果指定的 Enum.UserInputType 支持醫療回饋,則使用 Boolean 的 true

SetMotor

()

設置指定的 inputTypevibrationMotor 的振動強度。請注意,幾乎所有使用案例都指定 Enum.UserInputType.Gamepad1inputType,這會內部映射到裝置的相應硬件。

參數

指定的 Enum.UserInputType

預設值:""
vibrationMotor: Enum.VibrationMotor

指定的 Enum.VibrationMotor

預設值:""
vibrationValues: Tuple

馬達應該有多強烈地震動。只使用 tuple 中的第一值,該值應該是數字。

預設值:""

返回

()

範例程式碼

這個例子使小型馬達根據左觸發器受到的壓力量大小振動,大型馬達根據右觸發器受到的壓力量大小振動。

醫療服務:設置馬達()

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)

活動