Skip to content

Handling Collisions

Alvin Aggrey edited this page Feb 7, 2023 · 19 revisions

Overview

Detects and responds to collisions between game-objects. The collision handler can handle to shapes of colliders, a circle and a box (the box is Axis Aligned).

image

In order for the collision handler to monitor collisions between a collider, it must be added to the collision handler by using AddCollider.


Triggers

If toggled on the handler will allow game-objects to pass through or stay inside Colliders. However the collision handler will still recognise any intersections with other colliders as collisions.

Responding to Collisions

Collision Events are an interface for responding to collisions of a particular collider. This is separate from the pre-existing event system in the game engine. There are two events that every collider has OnEnter and OnLeave, as their names state they are triggered every time a collider enters/collides with the target collider or stops colliding with the target collider.

Example of Use

void A::foo(Collider&)
{
	std::cout << "Hello" << std::endl;
}

void loo(Collider&)
{
	std::cout << "World" << std::endl;

}

void A::boo()
{
	CollisionHandler collisionhandler;
	BoxCollider box;
	collisionhandler.AddCollider(std::make_shared<BoxCollider>(box));
	std::function<void(Collider&)> f = std::bind(&A::foo, *this, std::placeholders::_1);
	box.AddOnEnterCallback(f);
	box.AddOnEnterCallback(loo);
}

Layers

Layers effect the what colliders a collider can interact with. Currently there are 4 layers that you can set a collider to:

  • Decoration
  • Player
  • Enemy
  • Projectile

Filtering Collisions

The are three ways that end-users can specify that that dont want to check collisions against specific objects.

CollisionMatrix

The most broad way to do this is to set the collision matrix on the collision handler. Each collider exist on a specified layer in the game engine (Decoration, Player, Enemy, Projectile). Defining the Collision matrix specifies what layers can interact so collisions on these layers wont be detected.

For Instance Enemy layer to Enemy layer interactions maybe set to false to prevent enemies getting stuck to each other.

Collision Mask

All colliders have their own collision mask. This is specifies layers that a collider is allowed to interact with.

For instance player mask could be set to not interact with projectiles for a few seconds, as a way of providing Invincibility frames after taking a hit.

Blacklisting

Lastly blacklisting allows you to specifically ignore collisions against specific objects and not layers.

Priority

(Most to Least)

  1. Collision Matrix
  2. CollisionMask
  3. Blacklist

This means that if you set your collision mask to interact with objects on the projectile layer, but the collision matrix is set to

Currently filters can only be set through code and not the editor


Page Author: Alvin Aggrey