0
votes

I am making a simple game, using Sprite Kit and physics.

The problem is actually very simple, to my knowledge Sprite Kit allows to set gravity on physicsWorld, but I need to set gravity on physicsBodies in a way that a larger/heavier body influences everyone around it. By the life of me, I cannot find a feature to do this and before I start programming custom physics into the game, I want to know if anyone here knows of a standard way to do this.

3
there is no built-in way to do this, it's enumerating bodies and applying an impulse based on their relative distance to the target every update:LearnCocos2D

3 Answers

3
votes

You are looking for the SKFieldNode. There are different kinds of fields you can create, but it sounds like what you want would be a radialGravityField.

You can find out more at the linked Class Reference.

0
votes

For each node, iterate over all other nodes in the scene and compute the net force acting on that node from the acceleration due to gravity. You can then applyForce to that node.

-1
votes

There are some new additions to SpriteKit in iOS 8, including numerous enhancements to physics. If you can target your game to iOS 8 and later, I suggest you check out the beta.