Hology
Hology 文檔
Hology 文檔
  • 👋歡迎來到Hology文檔
  • Getting started
    • Hology Engine簡介
    • 第一步指南
    • 編輯器基礎指南
      • 在場景中飛行
      • 放置物件
      • 選擇物件
      • 變換
      • 分組物件
      • 複製
    • 入門遊戲模板 - 第三人稱射擊遊戲
  • Tutorials
    • 滾球 - 遊戲玩法編程
    • 角色動畫程式設計
    • Character AI behavior
  • Release
    • 遊戲發行
      • Discord Activities
      • 臉書即時遊戲
      • 上傳至 Itch.io
      • 使用 GitHub Pages
      • 發布到Steam
      • iOS 和 Android
  • Assets
    • 3D模型
      • 客製化碰撞形狀
      • 材質自訂分配
    • 材質
    • 紋理
    • 預製體
  • Gameplay
    • 演員(Actors)
      • 創建演員類
      • 演員參數
      • Actor 元件
      • Actor 的生命週期
      • 生成 Actors
      • 移動 Actors
    • 服務
      • 載入資產
    • Player input
    • Collision detection
    • Physics
      • Physics body types
      • Applying forces
      • Ray casting
    • Trigger volumes
    • Character movement
    • Pointer events
    • Animation
      • Animation system
      • Character Animation
      • Animation State Machine
    • Sound
      • Audio parameter
    • 世界
    • Navigation
  • Shaders
    • 著色器介紹
    • Creating shaders
    • 著色器參數
    • Typescript shaders
      • Types
      • Math functions
      • Attributes
      • Varying
      • Uniforms
      • Textures
      • Arrays
      • Select
      • Lighting
    • Painted materials
    • Water shader tutorial
  • Level design
    • 地形雕刻
    • 地形繪製
    • Grass
  • User Interfaces
    • 創建用戶界面UI
    • 使用 React
    • VR
  • Visual Effects
    • 視覺效果簡介
    • 視覺特效資產
  • Integrations
    • Arcweave
由 GitBook 提供支持
在本页
  • Using the PointerEvents service
  • Events
  • Targets
  • Methods
  • Event object
  1. Gameplay

Pointer events

You can capture pointer events from the mouse or touch to interact with 3D objects in your world. This can be done with the PointerEvents service which can be injected in other services, actors or components.

Using the PointerEvents service

To use the PointerEvents service, inject it in in your game code. In the following example we do it in the game service, but you may use it in any other service or actor. The PointerEvents service has many methods to subscribe to different types of events. In the example we are simply passing in the entire scene to detect clicking on any object. However, the methods support passing in specific objects, actors or actor types.

import { GameInstance, Service, PointerEvents, inject, World } from '@hology/core/gameplay';

@Service()
class Game extends GameInstance {
  private pointerEvents = inject(PointerEvents)
  private world = inject(World)

  onStart() {
    this.pointerEvents.onClickObject3D(this.world.scene).subscribe((event) => {
      console.log("Clicked at point: ", event.intersection.point)
    })
  }
}

Events

The following events can be subscribed to.

  • click - The object was clicked, meaning that the touch or mouse down event started and ended on the same object.

  • pointer down - The touch or mouse down event started on the object.

  • pointer up - The touch or mouse up event event ended on the object.

  • pointer enter - The touch or mouse pointer was moved onto the object. This event is only emitted once until the pointer leaves the object.

  • pointer leave - The touch or mouse pointer moved away from the object.

  • pointer move - The touch or mouse pointer is moving over the object. The event is emitted whenever the pointer moves.

Targets

When subscribing to events you can use different targets

  • Object3D - Any 3D object in the scene can be used for events.

  • Actor - A specific actor instance.

  • Actor type - An actor class to capture events from any instance of that type.

Methods

The following methods exist on the PointerEvents service for different types of events and targets.

  • onPointerEnterObject3D

  • onPointerEnterActor

  • onPointerEnterActorType

  • onPointerLeaveObject3D

  • onPointerLeaveActor

  • onPointerLeaveActorType

  • onClickObject3D

  • onClickActor

  • onClickActorType

  • onPointerDownActor

  • onPointerDownActorType

  • onPointerDownObject3D

  • onPointerUpActor

  • onPointerUpActorType

  • onPointerUpObject3D

  • onPointerMoveActor

  • onPointerMoveActorType

  • onPointerMoveObject3D

Event object

When an event happens, your callback function will receive an object containing information about the event.

  • object / actor - Depending on if you are using the Object3D or Actor variant, you will receive either the object or actor that was interacted with.

  • intersection - Information about the intersection of the raycast with the object.

    • distance: number - distance between the origin of the ray and the intersection

    • point: Vector3 - point of intersection, in world coordinates

    • face: Face - intersected face

    • object: Object3D - the intersected object

    • uv: Vector2 - U,V coordinates at point of intersection

    • uv2: Vector2 - Second set of U,V coordinates at point of intersection

上一页Character movement下一页Animation