How to handle entity collision in libGDX Ashley?

How to handle entity collision in libGDX Ashley?

I’m attempting to make a game with libgdx and ashley. I have a basic understanding of both and was wondering how to handle a entity collision. I saw a ContactListener in Box2D, but I am unsure of how to link this with entities in ashley.

How to detect collision with a specific object?

After we set a tag for the object, we can detect the specific object by its tag name. We will first check if our game object has the specified tag name and then destroy it on Collision with another Object. Below is our C# code to detect collision with a specific object in Unity: void OnCollisionEnter (Collision targetObj) {

Why do you need collision detection in Unity?

In the gaming world, we often may need to detect the collision between two objects. For example, in many games, we attack our enemies with the bullet. Our enemies destroy in the game because there is a collision detection between our enemy and bullet.

How does collision detection work in a 2D game?

Generally you will have a simple generic shape that covers the entity known as a “hitbox” so even though collision may not be pixel perfect, it will look good enough and be performant across multiple entities. This article provides a review of the most common techniques used to provide collision detection in 2D games.

Can you use scene2d and Ashley together in libGDX?

It’s a judgment call based on your particular use case. That being said, one reason why you typically wouldn’t use Scene2D and Ashley together is that they have a lot of overlap.

Is it bad to use Ashley with scene2d?

I don’t think you can say it’s always a bad idea to mix Scene2D and an ECS like Ashley. It may make a lot of sense to use Scene2D.UI for your user interface, and then Ashley for everything else. As you point out, there isn’t a technical reason why you couldn’t tie these two together. It’s a judgment call based on your particular use case.