# How to calculate final force vector for the SKSpriteNode

I am creating space game which has an effect similar to black hole's gravitational effect. Wherever the spaceship is going, the black hole will attract it, summing up all the vectors together.

I know SKFieldNode has a method customFieldWithEvaluationBlock: that allows to calculate everything myself, but might it be another way to do that?

I have tried almost every type in SKFieldNode, but nothing helped.

1. There are some side effects that don't suit me (i.e. If I use an electric or magnetic field, the object repels from the black hole)
2. Moreover, moving with SKAction (i.e. for the spaceship) doesn't allow me to sum all movement vectors together (I cant do - (void)moveTo:duration: actions simultaneously, even with grouping the actions)

What can you advice me? !

• Beraliv, I deleted greetings part because they are frowned upon by the community members. If you take a look at the other questions, you see what I an saying, please don't take it personally. Did you test vortexField? – Iman Sep 10 '15 at 17:53
• @lman thanks, I understood. Yeah, I tested it, need to adjust the parameters to check if it suits. – Beraliv Sep 10 '15 at 17:56
• did you succeed to use vortedField for your blackhole? please share your experiance. – Iman Sep 16 '15 at 21:28

## 1 Answer

to simulate a black hole, I suggest to use SKFieldNode and vortexField(), adjust its strength and falloff property (default is 2).

Setting a big number for strength will makes a big perpendicular force which simulates an angular force too (tangant to its imaginary orbital path around the black hole).

And let the physics handle the rest, just dont touch any thing else and only use physics rules.

Do not apply any force vector manually

• @lman I was helped with this stackoverflow.com/questions/31500104/… counting it myself, its close to what I wanted to. – Beraliv Sep 18 '15 at 12:02
• @Beraliv goodluck, but I don't understand why you couldn't use SpriteKit fields method, they are much more optimized than an update method code. – Iman Sep 18 '15 at 12:33
• @lman ok, how can I stop the spaceship around the blackhole and then try to scale it with this field? – Beraliv Sep 18 '15 at 12:35
• @Beraliv Scale what? I don't follow, You will have a black hole that its force increase by getting closer to it, and at a specfic distance your spaceship engine force and the blackhole gravity will be equal and the spaceship miss the chance to escape. a little before that if your space ship moves towards an orbital tangent direction the BH gravity and the spaceship tangent force will create an orbital path which I believe you are looking for. What do you mean by scale? do you mean how to increase black hole gravity? set strength property of your vortex – Iman Sep 18 '15 at 12:45