I have a basic rocket game that collects meteorites. Very basic. The game works fine except there is a real annoyance that i've been trying to iron out but can't.
When the rocket collides with a meteorite:
-(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair rocket:(CCNode *)nodeA meteorite:(CCNode *)nodeB{
[self meteoriteRemoved:nodeB];
[self spawnMeteorite];
score ++;
_scoreLabel.string = [NSString stringWithFormat:@"%d", score];
}
It is removed and respawned. This works fine, but if the meteorite is close to another meteorite and the rocket slams into one, it knocks the other one out of the way like snooker balls. I want them to remain stationary until the rocket collides with them.
Is there any way to tell sprites in the same collision group to ignore each other?
EDIT**
I'm loading the meteorites in a loop from a class which has:
@implementation Meteorite
- (void)didLoadFromCCB {
self.physicsBody.collisionType = @"meteorite";
}
@end
They are then spawned using:
-(void)spawnMeteorite{
CCNode *meteorite = [CCBReader load:@"Meteorite"];
CGFloat randomX = ((double)arc4random() / ARC4RANDOM_MAX);
CGFloat randomY = ((double)arc4random() / ARC4RANDOM_MAX);
CGFloat rangeX = 320 - 48;
CGFloat rangeY = 2880 - 200;
meteorite.position = ccp((randomX * rangeX)+24, (randomY * rangeY)+ _ground.contentSize.height + _rocket.contentSize.height);
meteorite.physicsBody.velocity = ccp(0,0);
[_physicsNode addChild:meteorite];
}
The following code gives a log of Meteorite Hit extremely often when flying into a group, and most of them fly off into oblivion!
-(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair meteorite:(CCNode *)nodeA meteorite:(CCNode *)nodeB{
NSLog(@"Meteorite HIT");
}
Thanks for looking into this, hope it helps