跳转至

鼠标点击射线检测(Deproject Screen to World + Line Trace)

点击鼠标时从屏幕位置反投影出一条世界空间射线,并用 Line Trace By Channel 检测命中的物体。

蓝图节点连法

鼠标点击射线检测蓝图

  1. 由输入事件触发(截图上方为 Enhanced Input 事件的 Action Value 输出)。
  2. Get Player Controller(Player Index = 0)的返回值接入 Deproject Screen to World 的 Player 输入。
  3. Screen Position 输入:用 Get Viewport Size 的返回值 Multiply(× 0.5,Make Literal Float),即取视口中心作为屏幕坐标。
  4. Deproject Screen to World 输出 World Position(射线起点)和 World Direction(射线方向)。
  5. World Direction 乘以 Make Literal Float(1000.0) 得到射线长度,再与 World Position 相加(Add)得到射线终点。
  6. 接 Line Trace By Channel:
    • Start = World Position
    • End = World Position + World Direction × 1000
    • Trace Channel = Visibility(可视性)
    • Draw Debug Type = 持久(Persistent,便于调试观察射线)

注意事项

  • 截图中 Screen Position 取的是 视口尺寸 × 0.5(屏幕中心),适合准星固定在屏幕中央的玩法;1000.0 是射线长度,可按需调大。
  • Draw Debug Type 设为持久仅用于调试,正式版本应改回 None。

ID:30 | 更新:2026-06-11