1
self.player.xScale = fabs(self.player.xScale)*multiplierForDirection2;

When I use turn the player to the left, he is unable to detect collisions from enemy2, but can detect it from enemy1 even though the BitMasks are the same for both. I ran into a similar problem and ended up having to create two different functions for the enemy moving left and the enemy moving right.
What exactly is xScale doing that is preventing collisions?

Larme
  • 24,190
  • 6
  • 51
  • 81

1 Answers1

0

I'm assuming this is spriteKit.... If you create a SKNode to act as the parent object of self.player, you can attach the collider to the SKNode and use xScale = -1 on the player. Something like this:

    SKNode *parent = [SKNode new];
    parent.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.player.frame.size];
    [parent addChild:self.player];
    self.player.xScale = -1;

Similar to having an empty game object to hold everything together. Unfortunately, some of your code might have to change to accommodate the new parent node.

Placus Brutus
  • 93
  • 1
  • 4