概要
方法
將目前的振動值設為指定的 UserInputType 和 Enum.VibrationMotor 。
返回 true 如果指定的馬達可以與指定的 Enum.UserInputType 一起使用。
如果指定的 Enum.UserInputType 支持震動回饋,返回 true 。
- SetMotor(inputType : Enum.UserInputType,vibrationMotor : Enum.VibrationMotor,vibrationValues : Tuple):()
設置指定的 UserInputType 和 Enum.VibrationMotor 的振動強度。
屬性
方法
GetMotor
將目前的振動值設為指定的 UserInputType 和 Enum.VibrationMotor 。如果 SetMotor() 先前未被呼叫,此方法將無法返回任何東西。
參數
指定的 Enum.UserInputType 。
指定的 Enum.VibrationMotor 。
返回
目前的振動值設為指定的 Enum.UserInputType 和 Enum.VibrationMotor 或 nil 如果 SetMotor() 尚未被呼叫。
IsMotorSupported
返回 true 如果指定的馬達可以與指定的 Enum.UserInputType 一起使用。
參數
正在檢查特定的 Enum.UserInputType 以獲得 Enum.VibrationMotor 協助持。
指定的 Enum.VibrationMotor 檢查是否支持指定的 Enum.UserInputType 。
返回
如果指定的馬達可以與指定的 Enum.UserInputType 一起使用,則 true ;否則,則 false 。
IsVibrationSupported
如果指定的 Enum.UserInputType 支持震動回饋,返回 true 。
參數
指定的 Enum.UserInputType 檢查是否支持醫療回饋。
返回
如果指定的 Enum.UserInputType 支持醫療回饋,則使用 Boolean 的 true 。
SetMotor
設置指定的 inputType 和 vibrationMotor 的振動強度。請注意,幾乎所有使用案例都指定 Enum.UserInputType.Gamepad1 為 inputType,這會內部映射到裝置的相應硬件。
參數
指定的 Enum.UserInputType 。
指定的 Enum.VibrationMotor 。
馬達應該有多強烈地震動。只使用 tuple 中的第一值,該值應該是數字。
返回
範例程式碼
This example makes the small motor vibrate depending on how much pressure is applied to the left trigger, and the large motor vibrate depending on how much pressure is applied to the right trigger.
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
-- Watch this input manually to accurately update the vibration motor
cachedInputs[input] = input.Changed:Connect(onInputChanged)
end
end
end
end
UserInputService.InputBegan:Connect(onInputBegan)