Search code examples
iossprite-kitphysicsgame-physicsskfieldnode

Create a SKNode attracted to larger node via an SKFieldNode without moving the larger node


In my game, I have a larger SKNode that uses an SKFieldNode radial gravity field to attract other, smaller nodes towards it. This results in the larger node being moved by the force of the smaller nodes, which isn't optimal for my game. (For reference, this is in a physicsWorld with no gravity).

Is there any way to attract nodes together in a field using SpriteKit without moving one particular one, and having it still respond in the physics simulation, so that they just stay touching the edge of the bigger node without impacting it?


Solution

  • While not a permanent fix, I've made a workaround of just setting the smaller nodes' mass to 0.0001 each (zero seems to restore the default behaviour), which works for my intended uses, but isn't a real fix to the general problem.