diff --git a/cocos/2d/CCNode.cpp b/cocos/2d/CCNode.cpp index ac19c48c8c..634e966a96 100644 --- a/cocos/2d/CCNode.cpp +++ b/cocos/2d/CCNode.cpp @@ -129,6 +129,7 @@ Node::Node(void) , _updateTransformFromPhysics(true) , _physicsWorld(nullptr) , _physicsBodyAssociatedWith(0) +, _physicsRotationOffset(0.0f) #endif , _displayedOpacity(255) , _realOpacity(255) @@ -2078,6 +2079,7 @@ void Node::setPhysicsBody(PhysicsBody* body) _physicsBody = body; _physicsScaleStartX = _scaleX; _physicsScaleStartY = _scaleY; + _physicsRotationOffset = _rotationZ_X; _physicsBodyAssociatedWith++; auto parentNode = this; @@ -2116,7 +2118,7 @@ void Node::updatePhysicsBodyTransform(const Mat4& parentTransform, uint32_t pare parentTransform.transformPoint(vec3, &ret); _physicsBody->setPosition(Vec2(ret.x, ret.y)); _physicsBody->setScale(scaleX / _physicsScaleStartX, scaleY / _physicsScaleStartY); - _physicsBody->setRotation(_physicsRotation); + _physicsBody->setRotation(_physicsRotation - _physicsRotationOffset); } for (auto node : _children) @@ -2139,7 +2141,7 @@ void Node::updateTransformFromPhysics(const Mat4& parentTransform, uint32_t pare setPosition(ret.x, ret.y); } _physicsRotation = _physicsBody->getRotation(); - setRotation(_physicsRotation - _parent->_physicsRotation); + setRotation(_physicsRotation - _parent->_physicsRotation + _physicsRotationOffset); _physicsWorld->_updateBodyTransform = updateBodyTransform; } diff --git a/cocos/2d/CCNode.h b/cocos/2d/CCNode.h index 0318570ea1..c2e92a333d 100644 --- a/cocos/2d/CCNode.h +++ b/cocos/2d/CCNode.h @@ -1842,6 +1842,7 @@ protected: PhysicsWorld* _physicsWorld; /** The PhysicsWorld associated with the node.*/ int _physicsBodyAssociatedWith; /** The count of PhysicsBody associated with the node and children.*/ + float _physicsRotationOffset; /** Record the rotation value when invoke Node::setPhysicsBody.*/ #endif // opacity controls diff --git a/cocos/physics/CCPhysicsWorld.cpp b/cocos/physics/CCPhysicsWorld.cpp index e67e90cd70..64ad7e4795 100644 --- a/cocos/physics/CCPhysicsWorld.cpp +++ b/cocos/physics/CCPhysicsWorld.cpp @@ -817,11 +817,6 @@ void PhysicsWorld::step(float delta) void PhysicsWorld::update(float delta, bool userCall/* = false*/) { - if (delta < FLT_EPSILON) - { - return; - } - if(_updateBodyTransform || !_delayAddBodies.empty()) { _scene->updatePhysicsBodyTransform(_scene->getNodeToParentTransform(), 0, 1.0f, 1.0f); @@ -832,12 +827,17 @@ void PhysicsWorld::update(float delta, bool userCall/* = false*/) { updateBodies(); } - + if (!_delayAddJoints.empty() || !_delayRemoveJoints.empty()) { updateJoints(); } + if (delta < FLT_EPSILON) + { + return; + } + if (userCall) { cpSpaceStep(_cpSpace, delta);