Parent-Child Physics body position in Cocos 3.4

Hi guys,

i updated Cocos lib to 3.4 from 3.3, and i have problem…

I am creating sprite, setting physics body to it, and adding sprite to parent node. Then i am moving the parent node (change pos to -X) and the physics body (child and also child sprite itself) stays fixed on the screen as it would be not related to sprite, or to anything!

In 3.3, if i moved the parent node, its child Sprite moved, and Sprite’s physics body too…

What’s wrong? How should i manage it?

Here is sample code:

  auto spriteTmx = Sprite::create(); // or can be Node::create() 
  spriteTmx->setPhysicsBody(body);
  targetNode->addChild(spriteTmx, 1);

Then i am changing the pos of targetNode, and the physics bodies (child sprite) is fixed on the screen, while its parent is moving.

Looks like some bug of Parent-child positioning in 3.4, otherwise don’t know what to do if this is not bug but intention.

PS: if i add sprite to parent node without physics body, it works as expected. Child sprite is moved with parent.

Thx

I have the same problem

same problem…

Same problem :frowning:
anyone tested new 3.5?

I also experience this. Note that the order in which you add the child, apply the physics body and setPosition have no impact. I also tried addChild on one frame and waiting until the next frame to apply the physics body - no luck.

I posted the issue in the GitHub tracker:
https://github.com/cocos2d/cocos2d-x/issues/11618

I didnt test it but they said its fixed here

github fixed

It appears that the fix described is the removal of 6 lines from cocos/base/CCDirector.cpp

-#if CC_USE_PHYSICS

  •    if(physicsWorld)
    
  •    {
    
  •        physicsWorld->_updateBodyTransform = false;
    
  •    }
    

-#endif

However, it seems to be associated with a future release of Cocos2d-x (v.4).

In Cocos2d-x 3.5 those lines are not present yet the problem persists.

Ok, this is most bizarre:

This bug is happening in Cocos2d-JS v3.6!

This PR should be able to fix the issue

https://github.com/cocos2d/cocos2d-x/pull/12239