void RigidBody::OnMarkedDirty(Node* node) { // If node transform changes, apply it back to the physics transform. However, do not do this when a SmoothedTransform // is in use, because in that case the node transform will be constantly updated into smoothed, possibly non-physical // states; rather follow the SmoothedTransform target transform directly // Also, for kinematic objects Bullet asks the position from us, so we do not need to apply ourselves if (!kinematic_ && (!physicsWorld_ || !physicsWorld_->IsApplyingTransforms()) && !smoothedTransform_) { // Physics operations are not safe from worker threads Scene* scene = GetScene(); if (scene && scene->IsThreadedUpdate()) { scene->DelayedMarkedDirty(this); return; } // Check if transform has changed from the last one set in ApplyWorldTransform() Vector3 newPosition = node_->GetWorldPosition(); Quaternion newRotation = node_->GetWorldRotation(); if (!newRotation.Equals(lastRotation_)) { lastRotation_ = newRotation; SetRotation(newRotation); } if (!newPosition.Equals(lastPosition_)) { lastPosition_ = newPosition; SetPosition(newPosition); } } }