I'm developing a 2D game with the new API Sprite Kit. The problem is that although setting the restitution of a sprite node to 0, it bounces a little bit. How can I totally disable the bouncing?
2 Answers
6
votes
You need to set the restitution on both the objects that will meet.
self.world = [SKNode node];
[self addChild:self.world];
self.backgroundColor = [SKColor colorWithRed:0.15 green:0.15 blue:0.3 alpha:1.0];
self.physicsBody = [SKPhysicsBody bodyWithEdgeFromPoint:CGPointZero toPoint:CGPointMake(500, 0)];
self.physicsBody.restitution = 0.0;
self.ball = [SKSpriteNode spriteNodeWithColor:[SKColor redColor] size:CGSizeMake(40, 40)];
self.ball.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(40, 40)];
self.ball.physicsBody.density = 100;
self.ball.physicsBody.restitution = 0.0;
self.ball.position = CGPointMake(200, 300);
[self.world addChild:self.ball];
1
votes
I found scaling the mass down works!
self.ball.physicsbody.mass=0.2;
Use a small number like that and it will not bounce, you will have to scale your gravity and impulses accordingly as well. I found 0.2 to work best with a grav of -20.
For whatever reason, even at 0 restitution, the average size objects are heavy enough to bounce.