我无法让我的墙物理体无法穿透。如果我的玩家节点物理体以较慢的“速度”与墙壁碰撞,它就会停止。但是,如果它以很快的“速度”前进,它就会穿过墙壁。我的播放器被PanGestureRecognizer
. 所谓速度,我的意思是如果突然“快速”滑动或者手势不是缓慢移动的平移手势,那么玩家就会穿过墙壁。这些是我的节点属性:
self.player.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.player.size];
self.player.physicsBody.categoryBitMask = SVGPlayerCategory;
self.player.physicsBody.contactTestBitMask = SVGWallCategory;
self.player.physicsBody.collisionBitMask = SVGWallCategory;
self.player.physicsBody.dynamic = YES;
self.player.physicsBody.usesPreciseCollisionDetection = YES;
self.player.physicsBody.velocity = CGVectorMake(0, 0);
self.leftWall.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:self.leftWall.size];
self.leftWall.physicsBody.categoryBitMask = SVGWallCategory;
self.leftWall.physicsBody.contactTestBitMask = SVGPlayerCategory;
self.leftWall.physicsBody.collisionBitMask = SVGPlayerCategory;
self.leftWall.physicsBody.dynamic = NO;
self.leftWall.physicsBody.resting = YES;
如果有帮助,这是我的移动方法:
-(void)dragPlayer: (UIPanGestureRecognizer *)gesture {
CGPoint translation = [gesture translationInView:self.view];
SKAction *move = [SKAction moveByX:translation.x y:-translation.y duration:0];
[self.player runAction:move];
[gesture setTranslation:CGPointMake(0, 0) inView:self.view];
}
有什么我想念的吗?