HapticService
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
概要
方法
現在の振動値を指定された UserInputType と Enum.VibrationMotor に設定して返します。
指定されたモーターが指定された Enum.UserInputType と一緒に使用できるように利用可能である場合、true を返します。
指定された Enum.UserInputType がハプティックフィードバックをサポートしている場合、true を返します。
- SetMotor(inputType : Enum.UserInputType,vibrationMotor : Enum.VibrationMotor,vibrationValues : Tuple):()
指定された UserInputType と Enum.VibrationMotor の振動強度を設定します。
プロパティ
方法
GetMotor
現在の振動値を指定された UserInputType と Enum.VibrationMotor に設定して返します。SetMotor() が以前に呼ばれていない場合、これは何も返しません。
パラメータ
指定された Enum.UserInputType 。
指定された Enum.VibrationMotor 。
戻り値
現在の振動値が指定された Enum.UserInputType または Enum.VibrationMotor または nil に設定され、SetMotor() が以前に呼び出されていない場合
IsMotorSupported
指定されたモーターが指定された Enum.UserInputType と一緒に使用できるように利用可能である場合、true を返します。
パラメータ
特定の Enum.UserInputType がサポートのためにチェックされています Enum.VibrationMotor 。
指定された Enum.VibrationMotor が指定された Enum.UserInputType をサポートしているかどうかをチェックしました。
戻り値
指定されたモーターが指定された true と一緒に使用できるかどうか、および指定された Enum.UserInputType ではない場合は、false です。
IsVibrationSupported
指定された Enum.UserInputType がハプティックフィードバックをサポートしている場合、true を返します。
パラメータ
指定された Enum.UserInputType がハプティックフィードバックをサポートしているかどうかをチェックしました。
戻り値
指定された true がハプティックフィードバックをサポートしている場合のブールン値 Enum.UserInputType 。
SetMotor
指定された inputType と vibrationMotor の振動強度を設定します。ほぼすべての使用ケースが、内部的にデバイスのそれぞれのハードウェアにマップされる inputType に対して Enum.UserInputType.Gamepad1 を指定していることに注意してください。
パラメータ
指定された Enum.UserInputType 。
指定された Enum.VibrationMotor 。
モーターがどれほど激しく振動するか。トゥプルの最初の値だけを使用し、それは数字であるべきです。
戻り値
コードサンプル
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)