HapticService

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

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

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

สรุป

วิธีการ

คุณสมบัติ

วิธีการ

GetMotor

ส่งค่าแรงสั่นสะเทือนปัจจุบันกลับไปยัง UserInputType และ Enum.VibrationMotor ที่ระบุนี้จะไม่ส่งคืนอะไรถ้า SetMotor() ไม่ได้รับการเรียกก่อน

พารามิเตอร์

ที่ระบุ Enum.UserInputType .

ค่าเริ่มต้น: ""
vibrationMotor: Enum.VibrationMotor

ที่ระบุ Enum.VibrationMotor .

ค่าเริ่มต้น: ""

ส่งค่ากลับ

มูลค่าการสั่นสะเทือนปัจจุบันถูกตั้งค่าเป็น Enum.UserInputType และ Enum.VibrationMotor หรือ nil หาก SetMotor() ไม่ได้รับการเรียกก่อนหน้านี้

IsMotorSupported

ส่งคืน true หากมอเตอร์ที่ระบุมีให้ใช้กับ Enum.UserInputType ที่ระบุไว้

พารามิเตอร์

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

ค่าเริ่มต้น: ""
vibrationMotor: Enum.VibrationMotor

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

ค่าเริ่มต้น: ""

ส่งค่ากลับ

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

IsVibrationSupported

ส่งคืน true หากสิ่งที่กำหนด Enum.UserInputType ข้อเสนอแนะ

พารามิเตอร์

การตรวจสอบที่ระบุ Enum.UserInputType ข้อเสนอแนะ

ค่าเริ่มต้น: ""

ส่งค่ากลับ

บูลีนของ true หากสิ่งที่กำหนด Enum.UserInputType ข้อเสนอแนะ

SetMotor

()

ตั้งความถี่ของการสั่นสะเทือนของ inputType และ vibrationMotor ที่ระบุโปรดทราบว่าเกือบทุกกรณีการใช้งานระบุ Enum.UserInputType.Gamepad1 สําหรับ inputType ซึ่งจะถูกแมพภายในเป็นฮาร์ดแวร์ของอุปกรณ์ตามลําดับ

พารามิเตอร์

ที่ระบุ Enum.UserInputType .

ค่าเริ่มต้น: ""
vibrationMotor: Enum.VibrationMotor

ที่ระบุ Enum.VibrationMotor .

ค่าเริ่มต้น: ""
vibrationValues: Tuple

ความถี่ที่มอเตอร์ควรสั่นสะเทือนอย่างหนัก ใช้เฉพาะค่าแรกใน tuple ซึ่งควรเป็นตัวเลข

ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

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

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)

อีเวนต์