This project has moved and is read-only. For the latest updates, please go here.

Identifying individual fixtures in collision

Topics: User Forum
Mar 3, 2011 at 3:01 AM

How do I identify during my own OnCollision event, which member of the fixturelist is experiencing the collision?

Mar 4, 2011 at 9:18 PM

The OnCollision delegate supplies you with the fixture that the delegate has been subscribed too and the fixture it is colliding with. What exactly do you need?

Mar 4, 2011 at 11:32 PM

Well what I'm doing is assigning all my fixtures userdata (i.e. "player" or "enemy") that I can identify in my OnCollision event and perform the proper actions.

My problem is I have one body containing 5 fixtures, and you can't assign the individual fixtures in the body userdata because assigning a value to one assigns it to them all.

so I have no idea how to identify which is being hit. how do I do this?

Mar 5, 2011 at 1:12 PM

Why not just use Body.UserData?

Fixtures user data are individual. Example:

Fixture1.UserData = "Enemy";
Fixture2.UserData = "Player";

That would make the first one have enemy and the second to have player. Nothing fancy here.

Mar 5, 2011 at 7:48 PM

K so weird ya, my problem was that I was assigning it to fixture.body.userdata rather than fixture.userdata

I was doing what you are talking about assigning a player the userdata "player" and enemy data "enemy" my issue was assigning the multiple fixtures within one body individual userdata.

for example on a car you would have 2 wheel fixtures and one body fixture. I got it working now though, doing player.FixtureList[0].userData = "part 1", .. "part2"... "part3"

thanks for the help.