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 提供支持
在本页
  • Physics System
  • Physical actors
  1. Gameplay

Physics

Hology Engine allows you to simulate physics with both dynamic and kinematic physics bodies. Beyond just collision detection, you can use physics to apply forces, control velocities, and dampening.

Physics System

Most of the physics functionality is accessed using the Physics System service. You can access this service by injecting it in your actor or actor component class.

import { Actor, BaseActor, PhysicsBodyType, PhysicsSystem, attach, inject } from "@hology/core/gameplay";

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

Physical actors

In order for actors to represent physical objects that can be moved using physics simulation or collide with other physical objects, they need to be added to the physics system. While this can be done automatically when using existing components such as MeshComponent and CharacterMovementComponent, you can also add the actor to the physics system yourself. You would normally do this if you are not using the previously mentioned component that does this for you.

import { Actor, BaseActor, PhysicsBodyType, PhysicsSystem, attach, inject } from "@hology/core/gameplay";

@Actor()
class ExampleActor extends BaseActor {
    private physics = inject(PhysicsSystem)
    
    onInit() {
        this.physics.addActor(this, [new BoxCollisionShape(1,1,1)], { 
            isTrigger: false,
            mass: 1,
            friction: 1,
            continousCollisionDetection: false,
            type: PhysicsBodyType.dynamic
          })
    }
}

When you add an actor you add a reference to the actor itself, followed by an array of at least one collision shape and some additional options. You can have multiple collision shapes to represent a more complex shape.

  • isTrigger - Whether it should just detect overlapping events

  • mass - The mass of the actor which affects how its velocity will change when colliding with other objects.

  • friction - A lower value will make other objects slide more easily.

  • continousCollisionDetection - Whether to enable continuous collision detection which is a bit more computationally expensive but can lead to better collision detection with fast objects.

  • type - Which type of physics body. Read more about Physics body types

上一页Collision detection下一页Physics body types