I’m using Cocos2d v3 and want to change a body from dynamic to static after colliding with another body. At the moment I’ve got:
-(void)ccPhysicsCollisionPostSolve:(CCPhysicsCollisionPair *)pair static:(CCNode *)nodeA wildcard:(CCNode *)nodeB
{
_player.physicsBody.type = CCPhysicsBodyTypeStatic;
}
or
-(BOOL)ccPhysicsCollisionPreSolve:(CCPhysicsCollisionPair *)pair static:(CCNode *)nodeA wildcard:(CCNode *)nodeB
{
_player.physicsBody.type = CCPhysicsBodyTypeStatic;
return YES;
}
but neither works. I get the error:
Aborting due to Chipmunk error: This operation cannot be done safely during a call to cpSpaceStep() or during a query. Put these calls into a post-step callback. Failed condition: !space->locked
I then tried to make a joint at the point of collision but it doesn’t work right.
Is there a way to change a body to dynamic as soon as it collides in v3? I can do it in later versions using Box2D. I want to stop gravity and other forces so it doesn’t move. I want to make it look like it stuck to a surface.
Read a little on post-step callbacks but i'm unfamiliar with how to use them.
Any help would be appreciated.