HapticService

Mostrar obsoleto

*Este contenido se traduce usando la IA (Beta) y puede contener errores. Para ver esta página en inglés, haz clic en aquí.

No creable
Servicio
No replicado

Resumen

Métodos

Propiedades

Métodos

GetMotor

Devuelve el valor de vibración actual establecido en el especificado UserInputType y Enum.VibrationMotor.Esto no devolverá nada si SetMotor() no se ha llamado antes.

Parámetros

El especificado Enum.UserInputType .

Valor predeterminado: ""
vibrationMotor: Enum.VibrationMotor

El especificado Enum.VibrationMotor .

Valor predeterminado: ""

Devuelve

El valor de vibración actual establecido al especificado Enum.UserInputType y Enum.VibrationMotor o nil si SetMotor() no se ha llamado antes.

IsMotorSupported

Devuelve true si el motor especificado está disponible para ser utilizado con el especificado Enum.UserInputType.

Parámetros

El específico Enum.UserInputType que se está verificando para el Soportede Enum.VibrationMotor.

Valor predeterminado: ""
vibrationMotor: Enum.VibrationMotor

El especificado Enum.VibrationMotor verificado para ver si soporta el especificado Enum.UserInputType .

Valor predeterminado: ""

Devuelve

Booleano de true si el motor especificado está disponible para ser utilizado con el especificado Enum.UserInputType , false si no.

IsVibrationSupported

Devuelve true si el especificado Enum.UserInputType admite opiniónháptica.

Parámetros

El especificado Enum.UserInputType verificado para ver si soporta comentarios opinión.

Valor predeterminado: ""

Devuelve

Booleano de true si el especificado Enum.UserInputType admite opiniónháptica.

SetMotor

()

Establece la intensidad de vibración del especificado inputType y vibrationMotor.Tenga en cuenta que casi todos los casos de uso especifican Enum.UserInputType.Gamepad1 para inputType que se mapea internamente al hardware respectivo del dispositivo.

Parámetros

El especificado Enum.UserInputType .

Valor predeterminado: ""
vibrationMotor: Enum.VibrationMotor

El especificado Enum.VibrationMotor .

Valor predeterminado: ""
vibrationValues: Tuple

Cuán intensamente debe vibrar el motor. Solo usa el primer valor en la tupla, que debe ser un número.

Valor predeterminado: ""

Devuelve

()

Muestras de código

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)

Eventos