Search code examples
iosswiftsprite-kitphysicsskfieldnode

Magnetic field affects unwanted sprite


I have a Player Sprite which moves as the user drag their finger across the screen. I have implemented a power that the player sprite creates a magnetic repulsive force around it. My dilemma is that when the power is turned on the player sprite itself gets affect my it when it shouldn't be.

I have set the correct fieldBitMask and categoryBitMask on the desired sprites and the field node but still doesn't work. This is my players physicsBody configuration:

physics.affectedByGravity = false
physics.allowsRotation = false
physics.dynamic = true;
sprite.physicsBody?.fieldBitMask = 0

Solution

  • Set player node:

    physics.dynamic = false