Reputation: 43
I am building a little game, but have a problem. I made some balls which bounce in the screen, it's the intention that the bounce in the screen with the same speed. My problem is the fact that after like 30 seconds the balls go crazy en bounce over the screen as fast as possible. How can I fix it?
Here's my code:
int maxXCoord = self.frame.size.width;
int maxYCoord = self.frame.size.height;
int circleWidth = 6;
int x = arc4random() % (maxXCoord - (circleWidth / 2));
int y = arc4random() % (maxYCoord - (circleWidth / 2));
SKSpriteNode* _numberint = [SKSpriteNode spriteNodeWithImageNamed: @"red.png"];
_numberint.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:(_numberint.frame.size.width/2)];
_numberint.position = CGPointMake(x,y);
_numberint.physicsBody.contactTestBitMask = ballCatagoryName;
_numberint.physicsBody.collisionBitMask = ballCatagoryName;
_numberint.physicsBody.friction = 0.8f;
_numberint.physicsBody.restitution = 1.2f;
_numberint.physicsBody.linearDamping = 0.0f;
_numberint.physicsBody.angularDamping = 0.0f;
_numberint.physicsBody.allowsRotation = NO;
[_numberint.physicsBody applyImpulse:CGVectorMake(8.0f, -8.0f)];
[self addChild:_numberint];
Thank you!
Upvotes: 0
Views: 42
Reputation: 64477
If you set restitution to values above 1.0 the objects will pick up speed with every collision. Set restitution to 1.0 or below.
Upvotes: 1