diff --git a/core/src/objects/part/basepart.cpp b/core/src/objects/part/basepart.cpp index 3cd1163..5052a7d 100644 --- a/core/src/objects/part/basepart.cpp +++ b/core/src/objects/part/basepart.cpp @@ -58,15 +58,13 @@ void BasePart::OnWorkspaceRemoved(std::shared_ptr oldWorkspace) { } void BasePart::onUpdated(std::string property) { - // Reset velocity - if (property != "Velocity") - velocity = Vector3::ZERO; + bool reset = property == "Position" || property == "Rotation" || property == "CFrame" || property == "Size" || property == "Shape"; if (workspace()) workspace().value()->SyncPartPhysics(std::dynamic_pointer_cast(this->shared_from_this())); // When position/rotation/size is manually edited, break all joints, they don't apply anymore - if (property != "Anchored") + if (reset) BreakJoints(); } diff --git a/core/src/partassembly.cpp b/core/src/partassembly.cpp index 83eefbb..3d44375 100644 --- a/core/src/partassembly.cpp +++ b/core/src/partassembly.cpp @@ -68,7 +68,9 @@ void PartAssembly::SetCollisionsEnabled(bool enabled) { void PartAssembly::SetOrigin(CFrame newOrigin) { for (auto part : parts) { part->cframe = newOrigin * (_assemblyOrigin.Inverse() * part->cframe); + part->velocity = 0; // Reset velocity part->UpdateProperty("CFrame"); + part->UpdateProperty("Velocity"); // sendPropertyUpdatedSignal(part, "CFrame", Variant(part->cframe)); } @@ -78,12 +80,15 @@ void PartAssembly::SetOrigin(CFrame newOrigin) { void PartAssembly::TransformBy(CFrame transform) { for (auto part : parts) { part->cframe = transform * part->cframe; + part->velocity = 0; // Reset velocity part->UpdateProperty("CFrame"); part->UpdateProperty("Position"); part->UpdateProperty("Rotation"); + part->UpdateProperty("Velocity"); sendPropertyUpdatedSignal(part, "CFrame", Variant(part->cframe)); sendPropertyUpdatedSignal(part, "Position", Variant(part->cframe)); sendPropertyUpdatedSignal(part, "Rotation", Variant(part->cframe)); + sendPropertyUpdatedSignal(part, "Velocity", Variant(part->cframe)); } _assemblyOrigin = transform * _assemblyOrigin; @@ -127,6 +132,7 @@ std::vector PartAssembly::GetCurrentTransforms() { t.part = part; t.cframe = part->cframe; t.size = part->size; + t.velocity = part->velocity; transforms.push_back(t); } diff --git a/core/src/partassembly.h b/core/src/partassembly.h index fc858a2..0753c1c 100644 --- a/core/src/partassembly.h +++ b/core/src/partassembly.h @@ -11,6 +11,7 @@ class Selection; struct PartTransformState { std::shared_ptr part; Vector3 size; + Vector3 velocity; CFrame cframe; }; diff --git a/editor/mainglwidget.cpp b/editor/mainglwidget.cpp index 3d3a0f0..5d72cf4 100755 --- a/editor/mainglwidget.cpp +++ b/editor/mainglwidget.cpp @@ -238,6 +238,7 @@ void MainGLWidget::handleLinearTransform(QMouseEvent* evt) { if (glm::any(glm::lessThan(glm::vec3(selectionAssembly.size() + abs(draggingHandle->normal) * diff), glm::vec3(0.001f)))) return; + // This causes the velocity to be reset even though it shouldn't, but it's not a huge deal, so whatevs. selectionAssembly.TransformBy(CFrame() + absDiff * 0.5f); selectionAssembly.Scale(selectionAssembly.size() + abs(draggingHandle->normal) * diff, diff > 0); } @@ -471,6 +472,7 @@ void MainGLWidget::mouseReleaseEvent(QMouseEvent* evt) { for (auto t : initialTransforms) { historyState.push_back(UndoStatePropertyChanged { t.part, "CFrame", t.cframe, t.part->cframe }); historyState.push_back(UndoStatePropertyChanged { t.part, "Size", t.size, t.part->size }); + historyState.push_back(UndoStatePropertyChanged { t.part, "Velocity", t.velocity, t.part->velocity }); } M_mainWindow->undoManager.PushState(historyState);