Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting Spritekit gravity source

Tags:

ios

sprite-kit

Is there any way to set an x,y coordinate that gravity pulls towards?

We want to suck a number of objects with physicsbodies towards a point as if it was a black hole.

like image 312
Max Hudson Avatar asked Aug 25 '26 23:08

Max Hudson


1 Answers

Not for the regular world gravity.

To achieve this effect, you have to apply to each body an impulse every frame. The strength and direction of the impulse depends on the distance of the body (node) to the gravity source's position.

like image 188
LearnCocos2D Avatar answered Aug 28 '26 12:08

LearnCocos2D