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 提供支持
在本页
  • Core concepts
  • Generating a Navmesh
  • Using navigation in gameplay
  1. Gameplay

Navigation

AI navigation enables non-player characters (NPCs) to move intelligently and interact with the game world. This involves creating systems that allow NPCs to traverse complex environments, avoid obstacles, and reach their goals in a realistic and efficient manner.

Core concepts

Pathfinding: Pathfinding is the process of determining the optimal path for an NPC from its current position to a target destination. This involves algorithms such as A* (A-star), Dijkstra's, and others, which calculate the shortest or most efficient route while considering various factors like terrain, obstacles, and NPC capabilities.

Navigation Meshes (Navmeshes): A navigation mesh (navmesh) is a simplified representation of the game environment used for pathfinding. It divides the walkable areas of the game world into a network of interconnected polygons. Navmeshes allow NPCs to navigate complex environments efficiently by providing a clear map of traversable areas and the connections between them.

Generating a Navmesh

To generate a Navmesh in your scene that adapts to the terrain and obstacles, you can simply ad the NavMesh actor to the scene. In the asset browser, filter on Actors and select NavMesh. Add it anywhere in the scene and it will generate a navmesh that can be used by the navigation service.

Using navigation in gameplay

When there is a Navmesh actor in the scene, the Navigation service can utilise it to calculate an optimal path between two points or find the nearest point on the Navmesh around a point.

In the example below, we create a simple actor that will find the path to the player actor and move itself toward the player by a configured movement speed every frame.


@Actor()
class AiCharacter extends BaseActor {

  private mesh = attach(MeshComponent, {
    object: new Mesh(
      new BoxGeometry(.5, .5, .5),
      new MeshStandardMaterial({color: 0xff0000})
    )
  })

  private navigation = inject(Navigation)
  private world = inject(World)

  private movementSpeed = .5

  onUpdate(deltaTime: number): void {
    const player = this.world.findActorByType(Character)

    const { success, path } = this.navigation.findPath(this.position, player.position)
    if (success) {
      const direction = path[1].clone().sub(this.position).normalize()
      this.position.addScaledVector(direction, deltaTime * this.movementSpeed)
    }
  }

}
上一页世界下一页著色器介紹