(Solved) [Box2d][Libgdx] How to detect 2 bodies in contactListener?

Hello guys!

So i have been trying to find some answers for my question but i failed to find one so i thought it will be a good idea to ask it here.

if (contact.getFixtureA().getBody().getUserData() == "G" && contact.getFixtureB().getBody().getUserData() =="B"){
			
			System.out.print("Landed");
			
		}

So the “G” stand for the “Ground” and the “B” stand for the “Ball” and when the ball collides with the ground it should say “Landed” but it does not do it can anyone please tell me what is my mistake?

Set the actual entity as the use data.

Then you can use fields within the entity to do comparisons.

Such as an enum, I personally use enums a lot to determine a type of object.

Umm…:persecutioncomplex:

Can you show me in code what do you mean?

Maybe check both cases,

if(contact.getFixtureA().getBody().getUserData() == "G" && contact.getFixtureB().getBody().getUserData() =="B")

as well as

if(contact.getFixtureA().getBody().getUserData() == "B" && contact.getFixtureB().getBody().getUserData() =="G")

Never compare Strings using “==” - use “equals” instead.

Thank you it worked!

And thanks for all of who helped me too.