2
votes

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.

1
Not sure what your exact issue is based on your brief description. If gravity is an issue, have you tried setting self.physicsBody.affectedByGravity = NO; ? - sangony
@sangony What I'm going for is an effect where the player can "land" on the block, after being pulled down by gravity, and not go through it. Kind of like a floor. - Tillson
Look into tmx maps. raywenderlich.com/62049/… - Roecrew

1 Answers

1
votes

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;