HarveyBrCo HarveyBrCo - 3 months ago 26
Swift Question

Swift Spritekit dissipating Gravity field

I have a game in swift using spritekit. If you tap the screen it will create a radial gravity field and pull all the other objects in. I create the gravity field like so

var fieldNode = SKFieldNode.radialGravityField();

fieldNode.falloff = 0.5;
fieldNode.strength = 1;
fieldNode.animationSpeed = 0.5;

It works but my problem is that I only want a sprite to be affected only when it is when it within a certain distance to the centre of the radial gravity, and i will have more than 1 sprite. The way I see it is that there are 2 ways to do it, 1. When a sprite is too far turn off the radial gravity for that sprite or 2. Make the radial gravity dissipate after a certain radius. There is also an overall gravity for the scene.

So the main question is:

How can I either turn off 1 gravity for a sprite OR make a radial gravity dissipate ?


A field node's region property determines its area of effect. The associated SKRegion object lets you define a circular region by its radius.

You can also use the fieldBitMask on a physics body and the categoryBitMask on a field to selectively control which fields affect which bodies.