I'm currently developing a game using typescript and the ECS design pattern. One of the challenges I'm facing is handling collisions between different entities within the game world.
I have an entity called Player
which comprises several components:
- LayerComponent - maintains the rendering layer name;
- PositionComponent - stores position coordinates;
- AppearanceComponent - contains rendering properties;
- BoxColliderComponent - defines the size of the AABB (Axis-Aligned Bounding Box) for collision detection.
Similarly, there is another entity named Enemy
with the same set of components. The key difference lies in the values stored in their respective LayerComponents
.
The Player
entity uses the value "Player" in its LayerComponent
, while the Enemy
entity utilizes the value "Enemy".
I am struggling to implement a mechanism that handles collisions between these entities effectively. It's crucial that they do not pass through each other in the game environment.
Currently, I've implemented a system called PlayerPosition
to manage collision detection and prevent entities from passing through one another by checking the BoxColliderComponent
. However, I believe this approach might be incorrect as collisions should ideally be handled by a separate dedicated system.
Here is the code snippet for PlayerPosition
:
// Code for PlayerPosition goes here