fix(part): velocity being overidden on run

This commit is contained in:
maelstrom 2025-07-21 17:16:56 +02:00
parent d79d4e3b4a
commit 6e387a72d2
4 changed files with 11 additions and 4 deletions

View file

@ -58,15 +58,13 @@ void BasePart::OnWorkspaceRemoved(std::shared_ptr<Workspace> 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<BasePart>(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();
}

View file

@ -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<PartTransformState> PartAssembly::GetCurrentTransforms() {
t.part = part;
t.cframe = part->cframe;
t.size = part->size;
t.velocity = part->velocity;
transforms.push_back(t);
}

View file

@ -11,6 +11,7 @@ class Selection;
struct PartTransformState {
std::shared_ptr<BasePart> part;
Vector3 size;
Vector3 velocity;
CFrame cframe;
};

View file

@ -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);