HapticService

사용되지 않는 항목 표시
만들 수 없음
서비스
복제되지 않음

Modern controllers and devices have motors built in to provide haptic feedback. Adding rumbles and vibrations can provide subtle feedback that is hard to convey through visuals or audio.

Roblox supports haptics for the following devices:

  • Android and iOS phones supporting haptics including most iPhone, Pixel, and Samsung Galaxy devices
  • PlayStation gamepads
  • Xbox gamepads
  • Quest Touch controller

요약

메서드

속성

메서드

GetMotor

Returns the current vibration value set to the specified UserInputType and Enum.VibrationMotor. This will not return anything if SetMotor has not been called prior.

매개 변수

The specified Enum.UserInputType.

vibrationMotor: Enum.VibrationMotor

The specified Enum.VibrationMotor.


반환

The current vibration value set to the specified Enum.UserInputType and Enum.VibrationMotor or nil if SetMotor has not been called prior.

IsMotorSupported

Returns true if the specified motor is available to be used with the specified Enum.UserInputType.

매개 변수

The specific Enum.UserInputType being checked for Enum.VibrationMotor support.

vibrationMotor: Enum.VibrationMotor

The specified Enum.VibrationMotor checked to see if it supports the specified Enum.UserInputType.


반환

True if the specified motor is available to be used with the specified Enum.UserInputType, false if not.

IsVibrationSupported

Returns true if the specified Enum.UserInputType supports haptic feedback.

매개 변수

The specified Enum.UserInputType checked to see if it supports haptic feedback.


반환

True if the specified Enum.UserInputType supports haptic feedback.

SetMotor

void

Sets the vibration intensity of the specified UserInputType and Enum.VibrationMotor. Note that almost all use cases specify Gamepad1 as the UserInputType.

매개 변수

The specified Enum.UserInputType.

vibrationMotor: Enum.VibrationMotor

The specified Enum.VibrationMotor.

vibrationValues: Tuple

How intensely the motor should vibrate. Only uses the first value in the tuple, which should be a number.


반환

void

코드 샘플

HapticService:SetMotor

local UserInputService = game:GetService("UserInputService")
local HapticService = game:GetService("HapticService")
local cachedInputs = {} -- Note that we use a cache so we don't attach a Changed event more than once.
local keyToVibration = {
[Enum.KeyCode.ButtonL2] = Enum.VibrationMotor.Small,
[Enum.KeyCode.ButtonR2] = Enum.VibrationMotor.Large,
}
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 InputObject manually so we can accurately update the vibrationMotor.
local function onChanged(property)
if property == "Position" then
HapticService:SetMotor(inputType, vibrationMotor, input.Position.Z)
end
end
cachedInputs[input] = input.Changed:Connect(onChanged)
end
end
end
end
UserInputService.InputBegan:Connect(onInputBegan)

이벤트