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?
Asked
Active
Viewed 2,096 times
2 Answers
6
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];

DogCoffee
- 19,820
- 10
- 87
- 120
-
@DogCoffee Thanks, but that didn't completely solve the problem in my case. I can still see some "trembling" even though both ``restitution``s are set to zero. Similar is asked here (http://stackoverflow.com/questions/24315250/skphysicsbody-with-restitution-0-still-bounces). Do you have any idea how to completely "disable" bouncing? – damirstuhec Dec 07 '14 at 20:47
1
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.