我有玩家类别,敌人类别和墙壁类别。我希望我的敌人类别能够穿过我的墙壁类别,我希望我的玩家类别在撞墙时停止。我让我的玩家停在墙上,但我也无法阻止我的敌人与我的墙碰撞。我不确定为什么......这是我的代码:
static const int playerCategory =3;
static const int wallCategory = 2;
static const int enemyCategory = 1;
敌人代码:
self.physicsBody.dynamic = YES;
self.physicsBody.restitution = 0.2;
self.physicsBody.allowsRotation = NO;
self.physicsBody.categoryBitMask = enemyCategory;
self.physicsBody.collisionBitMask = playerCategory;
self.physicsBody.contactTestBitMask = playerCategory;
墙代码:
wallRight.physicsBody.dynamic = NO;
wallRight.physicsBody.allowsRotation = NO;
wallRight.physicsBody.categoryBitMask = wallCategory;
wallRight.physicsBody.collisionBitMask = playerCategory;
wallRight.physicsBody.contactTestBitMask = playerCategory;
玩家代码:
self.physicsBody.dynamic = YES;
self.physicsBody.restitution = 0.2;
self.physicsBody.allowsRotation = NO;
self.physicsBody.categoryBitMask = playerCategory;
self.physicsBody.collisionBitMask = wallCategory | enemyCategory;
self.physicsBody.contactTestBitMask = wallCategory | enemyCategory;
我错过了什么?