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 提供支持
在本页
  1. Gameplay
  2. 演員(Actors)

移動 Actors

在將 actor 添加到場景中(無論是通過編輯器放置還是在運行時生成)後,您可能想要將其移動到不同的位置或旋轉它。有兩種方法可以實現這一點:

  • 直接在 actor 上設置新的位置和旋轉。

  • 通過將 actor 添加到物理系統中並賦予動態或運動學物理體來模擬物理效果。

設置 Actor 的變換

如果您的物體不需要嚴格遵守物理定律,您可以簡單地使用 actor 的 position 和 rotation 屬性來設置位置和旋轉。這將更新物體的渲染變換,但不會在物理世界中更新它。要在物理世界中更新,您還需要通過物理系統應用 actor 的變換。

在下面的例子中,我們有一個 actor,它具有由碰撞形狀給出的渲染和物理表示。在每一幀中,我們根據速度和方向更新 actor 的位置。

@Actor()
class BallActor extends BaseActor {
    private physics = inject(PhysicsSystem)

    public speed = 0.4
    public direction = new THREE.Vector3(0,0,1)

    private mesh = attach(MeshComponent, {
      mass: 1,
      bodyType: PhysicsBodyType.static,
      object: new PhysicalShapeMesh(
          new SphereGeometry(.2, 20, 10),
          new MeshStandardMaterial({ color: 0xeff542 }),
          new SphereCollisionShape(.2))
    })
    
    onUpdate(deltaTime: number) {
        this.position.addScaledVector(this.direction, this.speed * deltaTime)  
        
        // Also update the physics system so that the physics body is updated
        this.physics.updateActorTransform(this)       
    }
    
}

上一页生成 Actors下一页服務

最后更新于2个月前