简体   繁体   中英

SpriteKit Solid Block

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.

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM