I'm making a game with SpriteKit that involves a hero bouncing on a surface in the positive x and y direction. The hero has this size:
CGSize heroSize = CGSizeMake(hero.size.width-140, hero.size.height-35);
hero.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:heroSize];
hero.physicsBody.usesPreciseCollisionDetection = YES;
and uses applyImpulse
to bounce in the positive x/y direction:
[self.physicsBody applyImpulse:CGVectorMake(xvelocity, yvelocity)];
SKAction *rotation = [SKAction rotateByAngle: -2.0/M_PI duration:.5];
[self runAction: rotation];
The ground has a friction level of 0.4 and restitution of .5. Because the hero rotates when bouncing, he will sometimes bounce backwards and have a negative X velocity. I was wondering if there is any way to prevent an SKSpriteNode
from moving in the -X direction. Would a solution be to create a better size for the physics body of my SKSpriteNode
? It seems like this could happen with any shape, but would be less likely with more circular objects. Any input is greatly appreciated.
Thanks