I'm working on a project where I have a node affected by gravity. I would like to be able to apply a vertical acceleration to this node without touching gravity. Pretty much like a hot air balloon that I would make go up or down while other objects are still normally affected by gravity.
balloon = Vehicle()
balloon.physicsBody = SKPhysicsBody(polygonFrom: path)
balloon.physicsBody?.affectedByGravity = true
I tried playing around with applyForce(_:)
and impulse but what I'd like is a proper acceleration and not a punctual impulse to defy gravity over time! Any suggestion?
What you're looking for are physics fields (SKFieldNode
), in Sprite Kit.
These provide the ability to influence objects with general forces, like wind, lift, black hole style attraction etc.
You can read about them here.
The really important consideration of how they can work is in this quote:
Physics bodies with affectedByGravity set to false are still affected by the gravity fields created by linearGravityField(withVector:) and radialGravityField().
But what they forgot to also make clear(er) is that objects influenced by gravity are ALSO influenced by these fields.