# How to detect collision between entities using Ashley?

I am developing a game using Libgdx and Ashley, and I would like to know the best way to detect collisions between different entities. Currently I have been using a ContactListener that detects contacts between different types of entities but I think this could negatively affect the performance of the game, especially considering that in a mobile application.

I would like to clarify that the type of contact I am wanting to perform is between the player and coins or entities in which it is not necessary to have a body.

I assume both the player and the coins are circles for easy collision detection. So you can use the method shown in this blog https://www.gamedevelopment.blog/collision-detection-circles-rectangles-and-polygons/ which is:

public boolean isCirclesColliding(Circle cir1, Circle cir2){
float sidea = Math.abs(cir1.x - cir2.x);
float sideb = Math.abs(cir1.y - cir2.y);
sidea = sidea * sidea;
sideb = sideb * sideb;
float distance = (float) Math.sqrt(sidea+sideb);
return true;
}
return false;
}


Now, to limit the amount of checks you are doing against player you can reject all coins that are too far from the player since any coin over player.radius + coin.radius cannot be touching.

if(coin.radius + player.radius < math.abs(player.x - coin.x)){
// only coins close enough on x axis enter here
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.28147053718566895, "perplexity": 1590.5995683123865}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2022-21/segments/1652662527626.15/warc/CC-MAIN-20220519105247-20220519135247-00036.warc.gz"}