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 中的第一值,該值應該是數字。

預設值:""

返回

()

範例程式碼

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.

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
-- Watch this input manually to accurately update the vibration motor
cachedInputs[input] = input.Changed:Connect(onInputChanged)
end
end
end
end
UserInputService.InputBegan:Connect(onInputBegan)

活動