I have two different fixed SKPhysicsBody in an SKScene. The only difference between the two is their categoryBitMask. One has a categoryBitMask of 512, the other 1024.
static const u_int32_t kWallCategory = 0x1 << 9; //512
static const u_int32_t kStructureCategory = 0x1 << 10; //1024
In my program, I have a standard contact handler called from -(void)didBeginContact:(SKPhysicsContact *)contact
that begins:
-(void)handleContact:(SKPhysicsContact*)contact {
SKPhysicsBody *bodyA = contact.bodyA;
SKPhysicsBody *bodyB = contact.bodyB;
int type1 = contact.bodyA.categoryBitMask;
int type2 = contact.bodyB.categoryBitMask;
In my program, I need to determine the contact vector between a dynamic body and one of the two fixed bodies. In order to do so, I access the contactNormal property of the SKPhysicsContact
CGVector c = contact.contactNormal;
What I noticed, though, was that the contact vectors were inconsistent and I determined this was because sometimes bodyA of the SKPhysicsContact was the fixed body, sometimes bodyA was the dynamic body.
For example, when a bullet (dynamic body) hits a building (fixed body) from the left, I want the contact vector to be (-1,0)
each time. Currently, the contact vector is sometimes (-1,0)
(from the left) and sometimes (1,0)
(from the right) all depending on which body contact.bodyA
is.
My question: given all else being equal (physics properties, etc.) what determines what is bodyA and what is bodyB in an SKPhysicsContact?