Search code examples
box2dsprite-kitskspritenodeskphysicsbodyrestitution

SKPhysicsBody with restitution 0 still bounces


I'm am trying to drop the SKSpriteNode with constant speed and without bouncing.

Here is the code I'm using:

SKSpriteNode *floor = [SKSpriteNode spriteNodeWithColor:[UIColor clearColor] size:CGSizeMake(self.size.width, 1)];
floor.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:floor.size];
floor.physicsBody.restitution = 0.0f;
floor.physicsBody.dynamic = NO;
floor.physicsBody.allowsRotation = NO;

SKSpriteNode* block = [SKSpriteNode spriteNodeWithTexture:[SKTexture textureWithImageNamed:imageName]];
block.position = CGPointMake(160, 300);
block.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:CGSizeMake(block.size.width - 2, block.size.height)];
block.physicsBody.dynamic = dynamic;
block.physicsBody.restitution = 0.0f;
block.physicsBody.allowsRotation = NO;

When I vary the restitution value, I can see the difference in block bouncing, but when it's zero it still bounces a little bit. When multiple blocks are stacked, the below blocks also bounce a little bit.

How can I totally disable bouncing?


Solution

  • After some trial and error I've discovered that the Physics Engine is not meant to be used if you want accurate positioning of your elements. That's why in my board game, I have re-implemented the code in order to make posit