HapticEffect

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

無法瀏覽

現代控制器和裝置具有內置馬達,用於提供觸覺反回饋。添加隆隆聲和振動可以提供難以通過視覺或聲音訊傳達的微妙反饋。

Roblox 支持以下裝置的觸感:

  • 支持震動的 Android 和 iOS 手機,包括大多數 iPhone、Pixel 和 Samsung Galaxy 裝置
  • 遊戲平台游戲手柄
  • Xbox 遊戲控制器
  • 任務觸控器

概要

屬性

方法

  • Play():()

    播放觸感效果。

  • 用於定義自訂波形為表並應用到醫療上的方法。

  • Stop():()

    停止觸覺效果。

屬性

Looped

平行讀取

是否持續地使用觸覺效果循環。


local Workspace = game:GetService("Workspace")
local effect = Instance.new("HapticEffect")
effect.Type = Enum.HapticEffectType.GameplayExplosion
effect.Looped = true
effect.Parent = Workspace
-- Start the haptic effect
effect:Play()
-- After two seconds, stop the effect
task.wait(2)
effect:Stop()

Position

平行讀取

Radius 一起,指定輸入裝置相對的影響位置,並有效地確定影響效果的範圍是否廣泛到附近的馬達。請注意,有些遊戲手柄沒有「小」和「大」兩種馬達,「遊戲手柄大左/右」在 PC 上不支持。


local Workspace = game:GetService("Workspace")
local effect = Instance.new("HapticEffect")
-- Set the position and radius of impact
effect.Position = Vector3.new(0.5, 0.5, 0)
effect.Radius = 1
effect.Parent = Workspace
effect:Play()

Radius

平行讀取

Position 一起,指定輸入裝置相對的影響範圍,並有效地確定影響附近發動機的影響範圍。請注意,有些遊戲手柄沒有「小」和「大」兩種馬達,「遊戲手柄大左/右」在 PC 上不支持。


local Workspace = game:GetService("Workspace")
local effect = Instance.new("HapticEffect")
-- Set the position and radius of impact
effect.Position = Vector3.new(0.5, 0.5, 0)
effect.Radius = 1
effect.Parent = Workspace
-- Play the haptic effect
effect:Play()
平行讀取

觸覺類輸入,例如 Enum.HapticEffectType.GameplayCollision 用於快速死亡的大規模即時隆隆聲。Enum.HapticEffectType.Custom讓您指定通過SetWaveformKeys()定義的醫療波形鑰匙來指定一個醫療波形。

Waveform

Roblox 指令碼安全性
平行讀取

方法

Play

()

播放觸感效果。


local Workspace = game:GetService("Workspace")
local effect = Instance.new("HapticEffect")
effect.Type = Enum.HapticEffectType.GameplayExplosion
effect.Parent = Workspace
-- Play the haptic effect
effect:Play()

返回

()

SetWaveformKeys

()

這個方法讓你能夠將自訂波形定義為表並應用到醫療上。


local Workspace = game:GetService("Workspace")
local effect = Instance.new("HapticEffect")
-- Set effect type to custom in order to define a waveform
effect.Type = Enum.HapticEffectType.Custom
effect.Parent = Workspace
-- Define the custom waveform curve through a table
local rampUpWaveform = {
FloatCurveKey.new(0, 0.3),
FloatCurveKey.new(100, 0.4),
FloatCurveKey.new(300, 0.8),
FloatCurveKey.new(400, 1.0)
}
-- Set waveform through the effect's method
effect:SetWaveformKeys(rampUpWaveform)

參數

keys: Array
預設值:""

返回

()

Stop

()

停止觸覺效果。


local Workspace = game:GetService("Workspace")
local effect = Instance.new("HapticEffect")
effect.Type = Enum.HapticEffectType.GameplayExplosion
effect.Looped = true
effect.Parent = Workspace
-- Start the haptic effect
effect:Play()
-- After two seconds, stop the effect
task.wait(2)
effect:Stop()

返回

()

活動