HapticService
*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.
Sommario
Proprietà
Metodi
Restituisce il valore attuale della vibrazione impostato al UserInputType e Enum.VibrationMotor specificato.
Restituisce true se il motore specificato è disponibile per essere utilizzato con il motore specificato Enum.UserInputType.
Restituisce true se il specificato Enum.UserInputType supporta il Riscontro/Replicatattile.
- SetMotor(inputType : Enum.UserInputType,vibrationMotor : Enum.VibrationMotor,vibrationValues : Tuple):()
Imposta l'intensità di vibrazione della specificata UserInputType e Enum.VibrationMotor.
Proprietà
Metodi
GetMotor
Restituisce il valore attuale della vibrazione impostato al UserInputType e Enum.VibrationMotor specificato.Questo non restituirà nulla se SetMotor() non è stato chiamato prima.
Parametri
Il Enum.UserInputType .
Il Enum.VibrationMotor .
Restituzioni
Il valore della vibrazione attuale impostato al valore specificato Enum.UserInputType e Enum.VibrationMotor o nil se SetMotor() non è stato chiamato prima.
IsMotorSupported
Restituisce true se il motore specificato è disponibile per essere utilizzato con il motore specificato Enum.UserInputType.
Parametri
Il particolare Enum.UserInputType viene controllato per il AssistenzaEnum.VibrationMotor .
Il specificato Enum.VibrationMotor controllato per vedere se supporta lo specificato Enum.UserInputType .
Restituzioni
Booleano di true se il motore specificato è disponibile per essere utilizzato con il motore specificato Enum.UserInputType , false se non è così.
IsVibrationSupported
Restituisce true se il specificato Enum.UserInputType supporta il Riscontro/Replicatattile.
Parametri
Il specificato Enum.UserInputType controllato per vedere se supporta il Riscontro/Replicatattile.
Restituzioni
Booleano di true se il Enum.UserInputType specificato supporta il Riscontro/Replicatattile.
SetMotor
Imposta l'intensità di vibrazione della specificata inputType e vibrationMotor.Si noti che quasi tutti i casi d'uso specificano Enum.UserInputType.Gamepad1 per inputType che viene mappato internamente sull'hardware rispettivo del Dispositivo.
Parametri
Il Enum.UserInputType .
Il Enum.VibrationMotor .
Quanto intensamente il motore dovrebbe vibrare. Utilizza solo il primo valore nella tupla, che dovrebbe essere un numero.
Restituzioni
Campioni di codice
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)