Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialEduardo Rojas
4,084 PointsError while detecting
My contact with the "Ground" is being detected until it reaches half of the object "ground"
1 Answer
Neil Shweky
5,022 PointsPaste your code, I'll take a look!
Eduardo Rojas
4,084 PointsEduardo Rojas
4,084 PointsThe declaration:
typedef NS_OPTIONS(uint32_t, VACollisionCategories){ VACollisionCategoryFigure = 1 << 0, // 0000 VACollisionCategoryTrampoline = 1 << 1, // 0010 VACollisionCategoryGround = 1 << 2, // 0100
};
My figure setUpPhysics method:
-(void)SetUpPhysicsBody{
}
My trampoline setUpPhysics method:
-(void)setUpPhysicsBody{ self.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.size]; self.physicsBody.affectedByGravity = NO; self.physicsBody.dynamic = NO; self.physicsBody.categoryBitMask = VACollisionCategoryTrampoline; self.physicsBody.collisionBitMask = 0; self.physicsBody.contactTestBitMask = VACollisionCategoryFigure; self.physicsBody.usesPreciseCollisionDetection = YES; }
And the detection in the view:
(void) didBeginContact:(SKPhysicsContact *)contact { SKPhysicsBody *firstBody, *secondBody; SKAction *moveByY = [SKAction moveToY:CGRectGetMaxY(self.frame)+32 duration:2];
if (contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask ) { firstBody = contact.bodyA; secondBody = contact.bodyB; } else { firstBody = contact.bodyB; secondBody = contact.bodyA; }
if ( firstBody.categoryBitMask == VACollisionCategoryFigure && secondBody.categoryBitMask == VACollisionCategoryTrampoline ) { NSLog(@"BAM!"); VAFigures *figure = (VAFigures *)firstBody.node;
} else if ( firstBody.categoryBitMask == VACollisionCategoryFigure && secondBody.categoryBitMask == VACollisionCategoryGround ) { NSLog(@"Hit ground!"); VAFigures *figure = (VAFigures *)firstBody.node; [figure removeFromParent];
}
}
//it also has this in the initWithSize method:
Thanks for checking and sorry i got busy this days...