Reputation: 8998
I have a 'Moon' which has a gravity field in it and the 'Moon' is set with 'affectedByGravity = NO' and does not get affected by the scene's gravity field.
However I have an 'Asteroid' which also has the 'affectedByGravity = NO' set and it still gets attracted to the 'Moon' but not to the scenes gravity field.
Is this a bug or have I misunderstood how 'affectedByGravity' works?
EDIT: Excerpt from Apple docs
Defining How Forces Affect a Physics Body affectedByGravity Property A Boolean value that indicates whether this physics body is affected by the physics world’s gravity and the gravity exerted by any physics fields in the scene.
Declaration SWIFT var affectedByGravity: Bool Discussion The physics world’s gravity property defines the gravitational forces applied to volume-based bodies in the scene. The default value is true. This property is ignored on edge-based bodies, which are already unaffected by gravity.
Import Statement import SpriteKit
Availability Available in iOS 7.0 and later.
Upvotes: 1
Views: 251
Reputation: 20274
The affectedByGravity
property is only for the scene's physicsWorld
, and not for a gravity field. If you want the asteroid to not be affected by the moon, you will have to set it's physicsBody's fieldBitMask
as 0 (or a value other than that of the gravity field's bitMask).
Read up on the Adding Physics Fields To Your Scene section in Apple's Documentation.
Upvotes: 6