HapticEffect

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

不可浏览

现代控制器和设备具有内置驱动器提供反馈,用于提供触觉反馈。添加隆隆声和振动可以提供难以通过视觉或音频传达的微妙反馈。

Roblox 支持以下设备的触觉:

  • 支持最新 iPhone、Pixel 和 Samsung Galaxy 设备的 Android 和 iOS 手机支持震动,包括大多数 iPhone、Pixel 和 Samsung Galaxy 设备
  • 游戏手柄 PlayStation
  • 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 用于快速死亡的大规模初始隆隆。 值允许您通过 定义的自定义波形键指定一种触觉,以便您通过 指定特定波形。

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()

返回

()

活动