最近我的sidescroller游戏在碰撞时开始出现奇怪的行为。
在使主题更清晰的主题中:
Hero.m
-(void)didLoadFromCCB{
self.physicsBody.collisionType = @"sophy";
self.physicsBody.collisionCategories = @[@"sophy"];
self.physicsBody.collisionMask = @[@"ground",@"rockWall",@"pit", @"orb",@"enemyAttack"];
self.summoningPillar = NO;
self.footNode = [self getChildByName:@"footsensor" recursively:NO];
self.footPosition = self.footNode.position;
self.foot = self.footNode.physicsBody;
self.foot.sensor = YES;
self.foot.collisionType = @"foot";
self.foot.collisionCategories = @[@"foot"];
self.foot.collisionMask = @[@"ground"];
CCPhysicsJoint* ankle = [CCPhysicsJoint connectedPivotJointWithBodyA:self.physicsBody bodyB:self.foot anchorA:self.footNode.position];
ankle.collideBodies = NO;
self.animationManager.delegate = self;
}
Enemy.m
-(void)setAttacking:(BOOL)attacking{
if (self.attacking == YES && attacking==YES) return;
_attacking = attacking;
if (attacking){
self.attackNode.name = @"sickle";
self.attackNode.physicsBody = [CCPhysicsBody bodyWithCircleOfRadius:30 andCenter:ccp(-10,0)];
self.attackNode.physicsBody.affectedByGravity = NO;
self.attackNode.physicsBody.allowsRotation = NO;
self.attackNode.physicsBody.type = CCPhysicsBodyTypeStatic;
self.attackNode.physicsBody.sensor = YES;
self.attackNode.physicsBody.collisionCategories = nil;
self.attackNode.physicsBody.collisionType = @"enemyAttack";
self.attackNode.physicsBody.collisionCategories = @[@"enemyAttack"];
self.attackNode.physicsBody.collisionMask = @[@"sophy"];
}
else{
self.attackNode.physicsBody = nil;
}
}
问题是
当两个物体都在移动时发生这种碰撞,如果英雄停止,武器朝向它,碰撞就会被忽略,显然不会调用处理它的委托方法。
有时它会不止一次发生,在第一次碰撞后,可以在以下视频中看到:
解决
动画的物理体必须是运动学类型,即使两个速度均为0,也要对其进行碰撞处理。
self.attackNode.physicsBody.type = CCPhysicsBodyTypeKinematic;
答案 0 :(得分:0)
我发现了什么问题。
动画的物理体必须是运动学类型,即使两个速度均为0,也要对其进行碰撞处理。
self.attackNode.physicsBody.type = CCPhysicsBodyTypeKinematic;