I have a sprite that I want to apply a constant force to, as opposed to reapplying that force every update, which is giving me strange results.
I have a sprite that has a mass of 60 kg and is affected by gravity. I want to apply a force that is equal to the force of gravity constantly. The way I'm doing it still causes the sprite to fall of the screen really fast because the force of gravity is somehow greater. I'm wondering how and when the force of gravity is applied, and if it is possible fore me to set a constant force on the object, similar to the force of gravity.
Currently, my scene looks like this:
#import "MyScene.h"
@interface MyScene ()
@property (nonatomic, strong)SKSpriteNode *parachutist;
@end
@implementation MyScene
- (id)initWithSize:(CGSize)size
{
if (self = [super initWithSize:size])
{
CGSize spriteSize = CGSizeMake(80.0f, 80.0f);
self.parachutist = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImageNamed:@"parachutist.png"] size:spriteSize];
[self addChild:self.parachutist];
self.parachutist.position = CGPointMake(CGRectGetMidX(self.frame), CGRectGetMidY(self.frame));
self.parachutist.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:spriteSize];
self.parachutist.physicsBody.dynamic = YES;
self.parachutist.physicsBody.mass = 60.0; // kg
self.parachutist.physicsBody.affectedByGravity = YES;
}
return self;
}
- (void)update:(NSTimeInterval)currentTime
{
// this ought to match the force of gravity
[self.parachutist.physicsBody applyForce:CGVectorMake(0.0f, 60.0f * 9.8f)];
}
@end