Two physical bodies do not contact if the physical property.

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.

+6
source share
1 answer

Non-dynamic (static) bodies never collide, they should not change their position in the first place.

Instead, set collisionBitMask to 0 if you do not want collisions to affect them. Refer to the SKPhysicsBody link .

+16
source

Source: https://habr.com/ru/post/957162/


All Articles