Hology
Hology
Hology
  • 👋Welcome to Hology Docs
  • Getting started
    • Introduction to Hology
    • The first steps
    • Editor basics
      • Flying in scenes
      • Placing objects
      • Select objects
      • Transform
      • Grouping objects
      • Duplicate
    • Starter project - Third person shooter
  • Tutorials
    • Rolling ball - Gameplay programming
    • Character movement programming
    • Character AI behavior
  • Release
    • Distribution
      • Discord Activities
      • Facebook Instant Games
      • Upload to Itch.io
      • Host with GitHub Pages
      • Publishing to Steam
      • iOS and Android
  • Assets
    • 3D Models
      • Custom collision shapes
      • Material slots
    • Materials
    • Textures
    • Prefabs
  • Gameplay
    • Actors
      • Creating actor classes
      • Actor parameters
      • Actor components
      • Actor lifecycle
      • Spawning actors
      • Moving actors
    • Services
      • Load assets
    • 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
    • World
    • Navigation
  • Shaders
    • Introduction to shaders
    • Creating shaders
    • Shader parameters
    • Typescript shaders
      • Types
      • Math functions
      • Attributes
      • Varying
      • Uniforms
      • Textures
      • Arrays
      • Select
      • Lighting
    • Painted materials
    • Water shader tutorial
  • Level design
    • Landscape sculpting
    • Landscape painting
    • Grass
  • User Interfaces
    • Creating user interfaces
    • Using React
    • VR
  • Visual Effects
    • Introduction to VFX
    • VFX Assets
  • Integrations
    • Arcweave
Powered by GitBook
On this page
  • 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

PreviousCollision detectionNextPhysics body types

Last updated 11 months ago