contact points have two shapes, shape1 and shape2... but they are not guaranteed to be the shapes you expect them to be. for instance, lets say you have a ball and a ground, and say another static ball to bounce off. On first collision the ball hits the static ball. A contact is generated and shape1 is the ball, shape2 is the static ball. However, when it hits the ground, shape1 is the ground, shape2 is the ball.
This is arbitrary and while it 'could' be random, I suspect it is a little more deterministic than that. It may just be that the processing of contacts between sphere and sphere allways returns one thing, while contact with a sphere and a poly might return a different order. There are a lot of ways you can deal with this but the simplest( and albiet a bit messy ) is:
I'm not fond of this myself since its duplicating code, but it should serve to help point out where I think the problem is.
This is arbitrary and while it 'could' be random, I suspect it is a little more deterministic than that. It may just be that the processing of contacts between sphere and sphere allways returns one thing, while contact with a sphere and a poly might return a different order. There are a lot of ways you can deal with this but the simplest( and albiet a bit messy ) is:
Code:
if( shape1.GetBody().getUserData() is Player && shape1.GetBody().getUserData() is Obstacle )
{
... do something with player as shape1 an obstacle as shape2;
}
else if( shape1.GetBody().getUserData() is Obstacle && shape1.GetBody().getUserData() is Player )
{
... do the same thing but with player as shape2 and obstacle as shape1;
}
{
... do something with player as shape1 an obstacle as shape2;
}
else if( shape1.GetBody().getUserData() is Obstacle && shape1.GetBody().getUserData() is Player )
{
... do the same thing but with player as shape2 and obstacle as shape1;
}
I'm not fond of this myself since its duplicating code, but it should serve to help point out where I think the problem is.