Reputation: 530
I'm trying to make a solid platform/block where if the player lands on it, it just stands there. I have it using collisions, but it seems like there is an easier way.
What I'm going for is an effect where the player can "land" on the block, and not go through it.
if (firstBody.categoryBitMask == playerCategory && secondBody.categoryBitMask == endPlatformCategory) {
if (player.position.y > secondBody.node.position.y) {
player.physicsBody.velocity = CGVectorMake(player.physicsBody.velocity.dx, abs(player.physicsBody.velocity.dy*.5));
}
}
This code makes it fall back through after a few hits due to gravity, however.
Upvotes: 2
Views: 114
Reputation: 11696
If I understood you correctly, then try setting your player's physicsBody.collisionBitMask to interact with the block. Something like this:
self.physicsBody.collisionBitMask = CNPhysicsCategoryBlock;
and the block's physicsBody.collisionBitMask to interact with the player.
self.physicsBody.collisionBitMask = CNPhysicsCategoryPlayer;
Upvotes: 1