I have a node sprite that appears and falls in response to the gravity superimposed on it attached physicsBody.
Great.
Now I would like to use applyForceto push it a little in some direction while it falls.
Unfortunately, no matter how small I am doing physicsBody.massor physicsWorld.gravityis or how I'm doing the vector applyForce- vector applyForceseems to be ignored.
When I comment out a line self.physicsWorld.gravity , I see the applyForce work as expected
How to achieve a "push" of a physical body using applyForce with gravity?
Here is my .h
#import <SpriteKit/SpriteKit.h>
@interface GameScene : SKScene
@end
And .m
#import "GameScene.h"
@interface GameScene ()
@property NSMutableArray *bubblesToPop;
@end
@implementation GameScene
-(void)didMoveToView:(SKView *)view {
self.size = view.bounds.size;
self.physicsWorld.gravity = CGVectorMake(0, 1.0);
SKSpriteNode *sprite = [SKSpriteNode spriteNodeWithImageNamed:@"bubble"];
sprite.yScale = 0.5;
sprite.xScale = 0.5;
sprite.name = @"bubble";
sprite.position = CGPointMake(self.frame.size.width / 2.0, self.frame.size.height / 2.0);
SKPhysicsBody *physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:sprite.frame.size.width];
physicsBody.mass = 0.02;
[physicsBody applyForce:CGVectorMake(900, 900)];
sprite.physicsBody = physicsBody;
[self addChild:sprite];
}
@end