HapticService
*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.
I moderni controller e dispositivi hanno motori incorporati per fornire Riscontro/Replicatattili. L'aggiunta di rombi e vibrazioni può fornire feedback sottili che è difficile da trasmettere attraverso visualizzazioni o audio/suono.
Roblox supporta l'ottimizzazione per i seguenti dispositivi:
- Telefoni Android e iOS che supportano l'ottimizzazione dei pulsanti, tra cui la maggior parte degli iPhone, Pixel e dispositivi Galaxy
- PlayStation gamepads
- Controller Xbox
- Controller del touch della missione
Sommario
Proprietà
Metodi
Ritorna il valore di vibrazione corrente impostato all' UserInputType e Enum.VibrationMotor . Ciò non restituirà nulla se SetMotor non è stato chiamato prima.
Restituisce vero se il motore specificato è disponibile per essere utilizzato con il motore specificato Enum.UserInputType .
Restituisce vero se il Enum.UserInputType specificato supporta i Riscontro/Replicatattili.
- SetMotor(inputType : Enum.UserInputType,vibrationMotor : Enum.VibrationMotor,vibrationValues : Tuple):void
Imposta l'intensità di vibrazione del UserInputType e Enum.VibrationMotor .
Proprietà
Metodi
GetMotor
Ritorna il valore di vibrazione corrente impostato all' UserInputType e Enum.VibrationMotor . Ciò non restituirà nulla se SetMotor non è stato chiamato prima.
Parametri
Il specifico Enum.UserInputType .
Il Enum.VibrationMotor specificato.
Restituzioni
Il valore di vibrazione attuale impostato su Enum.UserInputType e Enum.VibrationMotor o nil se SetMotor non è stato chiamato prima.
IsMotorSupported
Restituisce vero se il motore specificato è disponibile per essere utilizzato con il motore specificato Enum.UserInputType .
Parametri
Il specifico Enum.UserInputType che viene controllato per il AssistenzaEnum.VibrationMotor .
Il Enum.VibrationMotor specificato controllato per vedere se supporta il Enum.UserInputType specificato.
Restituzioni
Verifichiamo se il motore specificato è disponibile per essere utilizzato con il motore specificato Enum.UserInputType , false se no.
IsVibrationSupported
Restituisce vero se il Enum.UserInputType specificato supporta i Riscontro/Replicatattili.
Parametri
Il Enum.UserInputType specificato è stato controllato per vedere se supporta i Riscontro/Replicatattili.
Restituzioni
Vero se il Enum.UserInputType specificato supporta i Riscontro/Replicatattili.
SetMotor
Imposta l'intensità di vibrazione del UserInputType e Enum.VibrationMotor . Nota che quasi tutti i casi d'uso specificano Gamepad1 come 2> Class.InputObject.UserInputType2> .
Parametri
Il specifico Enum.UserInputType .
Il Enum.VibrationMotor specificato.
Quanto deve rumorare il motore. 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)