Skip to content

Physics

acoox edited this page Apr 23, 2021 · 2 revisions

The sample game provided with the game engine is physics-based, which means that all movement and collisions is handled by a physics simulation. You are not required to use this in your game, so feel free to modify or remove the provided physics code. The popular Box2D library is used to simulate physics. Box2D documentation is highly recommended reading before writing any physics-related code.

Key Components

  • PhysicsComponent: This registers an entity as part of the physics engine and allows it to be moved around by physics.
  • ColliderComponent: Adds a collider to the entity, which lets it collide with other colliders (e.g. obstacles, enemies).
  • HitboxComponent: A simple subclass of ColliderComponent that creates a sensor-only collider. Useful for detecting collisions without actually colliding.
  • PhysicsMovementComponent: Provides movement for a physics-enabled entity by applying forces in the desired direction. This can steer an entity in a specific direction, and is used in the base game for the player and ghost enemies.
  • PhysicsEngine: Performs the actual physics simulation. You don't have to interact with this directly.

Key Features

  • Collision Events: All collisions trigger start/end events on the colliding entities. This can be used for combat hitboxes, triggering events when players enter areas, etc. See PhysicsContactListener (code).
  • Raycasting: Raycasting means firing a line in a certain direction and detecting any collisions. This is used in the sample game to calculate line of sight for enemies. See PhysicsEngine.raycast() (code).

Further Reading

Table of Contents

Home

Game

Game Home

Design Influences

Gameplay Features

Style

Story

Friendly Units
Map
City
Buildings
Unit Selections

Spell

Game User Testing: Theme of Unit Selection & Spell System

UI User Testing

Tutorial

Resource Stats Display

Loading Screen Bar

Health Bars
In Game menu
  • Feature
  • User Testing:In Game Menu

Landscape Tile Design

Landscape Tile Design Feedback

Weather Design

Weather Design Feedback

Camera Movement

Enemy design

Enemy Units

Enemy AI

How Animation Works

Map Flooding

Game Engine

Getting Started

Entities and Components

Service Locator

Loading Resources

Logging

Unit Testing

Debug Terminal

Input Handling

UI

Animations

Audio

AI

Physics

Game Screens and Areas

Terrain

Concurrency & Threading

Settings

Troubleshooting

MacOS Setup Guide

Clone this wiki locally