-
Notifications
You must be signed in to change notification settings - Fork 3
Handling Collisions
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).
In order for the collision handler to monitor collisions between a collider, it must be added to the collision handler by using AddCollider.
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.
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.
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 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
The are three ways that end-users can specify that that dont want to check collisions against specific objects.
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.
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.
Lastly blacklisting allows you to specifically ignore collisions against specific objects and not layers.
(Most to Least)
- Collision Matrix
- CollisionMask
- 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
© NINE BYTE WARRIORS | MIDNIGHT HARVEST