SpriteKit - Stop an object bouncing

ios, sprite-kit

Solution

You need to set the restitution property of SKPhysicsBody.

rock.physicsBody.restitution = 0.0;

According to Apple's Documentation:

This property is used to determine how much energy the physics body loses when it bounces off another object. The property must be a value between 0.0 and 1.0. The default value is 0.2.

Problem

How I stop and object that falls from the top of the screen to the bottom of the screen from bouncing. Here is the code for that object: ``` - (SKNode*)addRock { SKSpriteNode* rock = [SKSpriteNode spriteNodeWithImageNamed:@"asteroid"]; rock.position=CGPointMake ([self makeRandomXWBetween:0 and:self.size.width],self.size.height); rock.name = @"rock"; rock.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:rock.size]; rock.physicsBody.usesPreciseCollisionDetection = YES; rock.physicsBody.allowsRotation = NO; [self addChild:rock]; return self; } ```

Original source