Page 1 of 1

Problem with positioning node with body

Posted: Wed Sep 03, 2014 7:50 am
by dart_nikitos
Hello

I am using cocos2d v3.2 with Chipmunk, here is my problem:

There are two nodes with bodies ( NodeA, NodeB). I am moving NodeA with applyForce function, and i want NodeB to follow NodeA (be at the same place as NodeA). Both bodies are dynamic. My code:

-(void) update:(CCTime)delta
{
NodeB.position=NodeA.position;
}
It is OK when NodeA is not moving, but it start moving NodeB follows but positions are not exactly the same. Seems like it setts position with delay.

I've tried also Pivot Joint but result is almost the same.

Please help me if You know where is the problems.

Thanks!

Re: Problem with positioning node with body

Posted: Wed Sep 03, 2014 9:40 am
by slembcke
CCPhysics (which is not exactly Chipmunk) updates it's physics during the fixedUpdate: method. If you move the positioning call to that it might fix your problem.

What you are doing is a little odd though. Setting the position of a physics body every frame is asking it to "teleport" several times a second. It won't be moving smoothly, and it won't collide nicely with other objects. It sounds like you just want the second node to be a child node of the first instead of giving both of them physics bodies.