Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SpriteKit Fixed Joints

Tags:

ios

sprite-kit

I have a SKSpriteNode called "SpikyRedBall" which is a red ball. I wanted to add spikes to it so I used the following code. I can see the Spike attached to the ball but when the ball collides with another ball it does not take the fixed joints into consideration and moves them separately. I am using the following implementation:

@implementation SpikyRedBall

-(instancetype) init
{
    self = [super init];
    [self attachSpikes];
    return self;
}

    -(void) attachSpikes
    {
        Spike *spike = [[Spike alloc] init];
        spike.position = CGPointMake(0, 0);

        // attach the joint
        SKPhysicsJointFixed *ballAndSpikeJointFixed = [SKPhysicsJointFixed jointWithBodyA:self.physicsBody bodyB:spike.physicsBody anchor:CGPointZero];

        [self.scene.physicsWorld addJoint:ballAndSpikeJointFixed];
        [self addChild:spike];
    }

@end
like image 905
john doe Avatar asked May 30 '14 21:05

john doe


1 Answers

It sounds like you don't have collision or contact categories setup for the spikes themselves. I would try setting all physicsBody properties on the spikes to be identical to those of the balls, but obviously ensuring that they don't have collision or contact categories setup in a way that they would collide with their own parent ball.

like image 97
Cooper Buckingham Avatar answered Sep 24 '22 01:09

Cooper Buckingham