HapticService

Visualizza obsoleti

*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.

Non costruibile
Assistenza
Non Replicato

Sommario

Metodi

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

Valore predefinito: ""
vibrationMotor: Enum.VibrationMotor
Valore predefinito: ""

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 .

Valore predefinito: ""
vibrationMotor: Enum.VibrationMotor

Il specificato Enum.VibrationMotor controllato per vedere se supporta lo specificato Enum.UserInputType .

Valore predefinito: ""

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.

Valore predefinito: ""

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

Valore predefinito: ""
vibrationMotor: Enum.VibrationMotor
Valore predefinito: ""
vibrationValues: Tuple

Quanto intensamente il motore dovrebbe vibrare. Utilizza solo il primo valore nella tupla, che dovrebbe essere un numero.

Valore predefinito: ""

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.

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)

Eventi