Alright, newb question here but... I have been looking all over. Googled b2ContactListener and box2d collision and all that and I'm still fuzzy on this. How do you determine what you're colliding with? For example, say you have a player, a wall, and a bullet. I implemented my own b2ContactListener and I output some text when I have contact, but this goes off when *anything* has contact with anything. How do I tell specifically if the player is colliding with the wall, or the player is colliding with the bullet, or the bullet is colliding with the wall? Do I need to SetUserData to a pointer to the base actor class and then I could do like (pseudo-y code):
and then the actor class will have like... string name or unsigned int id? Then that way I could do:
This is the only way I can think of but it seems like it'll get messy fast. Sorry if this has been answered a billion times... I just was failing at finding anything more specific.
Code:
Actor* a1 = (Actor*)contact->GetFixtureA()->GetUserData();
Actor* a2 = (Actor*)contact->GetFixtureA()->GetUserData();
Actor* a2 = (Actor*)contact->GetFixtureA()->GetUserData();
and then the actor class will have like... string name or unsigned int id? Then that way I could do:
Code:
if(a1->name == "player" && a2->name == "bullet")
{
a1->Damage(a2->GetStrength());
a2->Kill();
}
{
a1->Damage(a2->GetStrength());
a2->Kill();
}
This is the only way I can think of but it seems like it'll get messy fast. Sorry if this has been answered a billion times... I just was failing at finding anything more specific.