There are two physical bodies: AirplaneNode :
- (id)initAirplaneNode { self = [super initWithImageNamed:@"airplane.png"]; if (self) { self.name = @"player"; self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.frame.size]; self.physicsBody.dynamic = NO; self.physicsBody.affectedByGravity = NO; self.physicsBody.categoryBitMask = AIRPLANE_CATEGORY; self.physicsBody.contactTestBitMask = BULLET_CATEGORY; } return self; }
and a BulletNode :
- (id)initBulletNode { self = [super initWithImageNamed:@"bullet.png"]; if (self) { self.name = @"bullet"; self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.frame.size]; self.physicsBody.dynamic = NO; self.physicsBody.usesPreciseCollisionDetection = YES; self.physicsBody.categoryBitMask = BULLET_CATEGORY; self.physicsBody.contactTestBitMask = AIRPLANE_CATEGORY; } return self; }
Both of them have a physicsBody.dynamic property set to NO .
The problem is when the bullet hits the plane, my SKScene does not call the didBeginContact method. However, if I specify the physicsBody.dynamic property for YES for AirplaneNode or BulletNode , the didBeginContact arrow.
Is there any way to fix this?
PS: I really do not need my nodes to be dynamic, because this causes undesirable behavior: the plane moves slightly when it is damaged, and sometimes the bullet rotates during the flight.
source share