HapticService

แสดงที่เลิกใช้งานแล้ว

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่

ไม่สามารถสร้าง
บริการ
ไม่ซ้ำ

การควบคุมและอุปกรณ์ในปัจจุบันมีมอเตอร์ที่สร้างขึ้นเพื่อให้การรับข้อเสนอแนะทางกายภาพ การเพิ่มเสียงดังและการสั่นสะเทือนสามารถให้ข้อเสนอแนะที่อ่อนโยนที่ยากที่จะสื่อสารผ่านวิดีโอหรือเสียง

Roblox รองรับการแกว่งตัวสำหรับอุปกรณ์ต่อไปนี้:

  • โทรศัพท์ Android และ iOS รองรับการแกว่งตัวรวมทั้งอุปกรณ์เสริมส่วนใหญ่ของ iPhone, Pixel และเครื่องสวมใส่ Galaxy ของ Samsung
  • แผงเกม PlayStation
  • แผงเกม Xbox
  • ตัวควบคุม Quest Touch

สรุป

วิธีการ

คุณสมบัติ

วิธีการ

GetMotor

กลับค่าตัวสัญญาณปัจจุบันที่ติดตั้งไว้ให้กับ UserInputType และ Enum.VibrationMotor นี่จะไม่กลับมาให้อะไรถ้า SetMotor

พารามิเตอร์

The specified Enum.UserInputType .

vibrationMotor: Enum.VibrationMotor

The specified Enum.VibrationMotor .


ส่งค่ากลับ

ค่าการสั่งการเครื่องสั่งที่กำหนดไว้ Enum.UserInputType หรือ nil ถ้า Enum.VibrationMotor ไม่ได้ถูกเรียกก่อนหน้านี้

IsMotorSupported

กลับ true หากมอเตอร์ที่กำหนดสามารถใช้ได้กับ Entity.UserInputType ที่กำหนด

พารามิเตอร์

Enzyme.UserInputType ที่ตรวจสอบสำหรับการสนับสนุน Enum.VibrationMotor

vibrationMotor: Enum.VibrationMotor

The specified Enum.VibrationMotor ตรวจสอบเพื่อดูว่ามันสนับสนุน Enum.UserInputType ที่กำหนด


ส่งค่ากลับ

จริงหากมอเตอร์ที่กำหนดสามารถใช้ได้กับมอเตอร์ที่กำหนดไว้ Enum.UserInputType หรือไม่

IsVibrationSupported

กลับ true หาก Enum.UserInputType ข้อเสนอแนะ

พารามิเตอร์

The specified Enum.UserInputType ข้อเสนอแนะ


ส่งค่ากลับ

จริงหาก Enum.UserInputType ข้อเสนอแนะhaptic

SetMotor

void

ตั้งค่าความเข้มของการสั่นของ UserInputType และ Enum.VibrationMotor โปรดทราบว่าเกือบทุกกรณีใช้งานระบุ Gamepad1 เป็น 2>Class.InputObject.UserInputType|UserInputType2>

พารามิเตอร์

The specified Enum.UserInputType .

vibrationMotor: Enum.VibrationMotor

The specified Enum.VibrationMotor .

vibrationValues: Tuple

ความเข้มของมอเตอร์ควรสัมพันธ์ ใช้ค่าตัวแรกในตัวอักษรที่เป็นตัวเลขเท่านั้น


ส่งค่ากลับ

void

ตัวอย่างโค้ด

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)

อีเวนต์