HapticService
*Este conteúdo é traduzido por IA (Beta) e pode conter erros. Para ver a página em inglês, clique aqui.
Resumo
Métodos
Retorna o valor de vibração atual definido para o especificado UserInputType e Enum.VibrationMotor.
Retorna true se o motor especificado estiver disponível para ser usado com o especificado Enum.UserInputType.
Retorna true se o especificado Enum.UserInputType suportar comentário/retornoháptico.
- SetMotor(inputType : Enum.UserInputType,vibrationMotor : Enum.VibrationMotor,vibrationValues : Tuple):()
Define a intensidade de vibração do especificado UserInputType e Enum.VibrationMotor.
Propriedades
Métodos
GetMotor
Retorna o valor de vibração atual definido para o especificado UserInputType e Enum.VibrationMotor.Isso não retornará nada se SetMotor() não foi chamado antes.
Parâmetros
O especificado Enum.UserInputType .
O especificado Enum.VibrationMotor .
Devolução
O valor de vibração atual definido para o especificado Enum.UserInputType e Enum.VibrationMotor ou nil se SetMotor() não foi chamado anteriormente.
IsMotorSupported
Retorna true se o motor especificado estiver disponível para ser usado com o especificado Enum.UserInputType.
Parâmetros
O específico Enum.UserInputType sendo verificado para SuporteEnum.VibrationMotor .
O especificado Enum.VibrationMotor verificado para ver se ele suporta o especificado Enum.UserInputType .
Devolução
Booleano de true se o motor especificado estiver disponível para ser usado com o especificado Enum.UserInputType , false se não.
IsVibrationSupported
Retorna true se o especificado Enum.UserInputType suportar comentário/retornoháptico.
Parâmetros
O especificado Enum.UserInputType verificado para ver se ele suporta comentário/retornoháptico.
Devolução
Booleano de true se o especificado Enum.UserInputType suportar comentário/retornoháptico.
SetMotor
Define a intensidade de vibração do especificado inputType e vibrationMotor.Observe que quase todos os casos de uso especificam Enum.UserInputType.Gamepad1 para inputType que é mapeado internamente para o hardware respectivo do dispositivo.
Parâmetros
O especificado Enum.UserInputType .
O especificado Enum.VibrationMotor .
Quão intensamente o motor deve vibrar. Apenas usa o primeiro valor na tupla, que deve ser um número.
Devolução
Amostras 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.
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)