0

I'm working on a game (with Cocos2d 3.0 and SpriteBuilder) in which a character smash another and gain impulse. To do this I'm trying the following:

-(BOOL)ccPhysicsCollisionPreSolve:(CCPhysicsCollisionPair *)pair hero:(CCNode *)hero goal:(CCNode *)goal {
    [hero.physicsBody applyImpulse:ccp(0.0f, 9000)];
    return TRUE;
}

And also:

-(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair hero:(CCNode *)hero goal:(CCNode *)goal {
    [hero.physicsBody applyImpulse:ccp(0.0f, 9000)];
}

But when the collision method is called, the character doesn't receive the impulse always. I also tried including the following inside "PostSolve" (How to make a dynamic body static in Cocos2d v3.0 with Chipmunk):

[[_physicsNode space] addPostStepBlock:^{
        [hero.physicsBody applyImpulse:ccp(0.0f, 9000)];
    } key:hero];

...but I have the same result. Do you hace any advice? Thank you.

Community
  • 1
  • 1
Jesod
  • 51
  • 7

1 Answers1

0

There was a rather embarrassing copy paste bug in apply impulse in v3 rc1. It's fixed in RC2 though.

slembcke
  • 1,359
  • 7
  • 7
  • Actually I'm using RC2. I also included the latest changes from Github: `-(void)applyImpulse:(CGPoint)impulse {_body.velocity = cpvadd(_body.velocity, cpvmult(CCP_TO_CPV(impulse), 1.0f/_body.mass));}` – Jesod Feb 23 '14 at 06:51
  • OK @slembcke this is really strange. I replaced CCPhysicsBody, CCPhysicsNode and CCPhysics+ObjectiveChipmunk with the GitHub version and everything works fine in the emulator, but doesn't work with an iPhone 5. – Jesod Feb 23 '14 at 07:42