Rohorao
Rohorao

Reputation: 79

How to set different gravities for different Spritenodes in Swift?

I have two different SKSpriteNodes in my scene. One node is a spaceship that is affected by the tilting of my device. The second node is a rock that should be falling down regardless of how my device is tilted. I have created both of these nodes separately (in separate projects) and they work fine. However, when I try to put them together in one project, the rock/asteroid starts being affected by the tilting of my device rather than just falling down. How can I make the asteroid fall down while still keeping the spaceship affected by the tilt of my device?

Upvotes: 1

Views: 66

Answers (1)

Steve Ives
Steve Ives

Reputation: 8134

You may want to read up on SKFieldNode (https://developer.apple.com/documentation/spritekit/skfieldnode). You can create new gravity nodes and, using category bt masks, have those nodes affect only the physics bodies that you specify.

Upvotes: 1

Related Questions