fix(part): velocity being overidden on run
This commit is contained in:
parent
d79d4e3b4a
commit
6e387a72d2
4 changed files with 11 additions and 4 deletions
|
@ -58,15 +58,13 @@ void BasePart::OnWorkspaceRemoved(std::shared_ptr<Workspace> oldWorkspace) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BasePart::onUpdated(std::string property) {
|
void BasePart::onUpdated(std::string property) {
|
||||||
// Reset velocity
|
bool reset = property == "Position" || property == "Rotation" || property == "CFrame" || property == "Size" || property == "Shape";
|
||||||
if (property != "Velocity")
|
|
||||||
velocity = Vector3::ZERO;
|
|
||||||
|
|
||||||
if (workspace())
|
if (workspace())
|
||||||
workspace().value()->SyncPartPhysics(std::dynamic_pointer_cast<BasePart>(this->shared_from_this()));
|
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
|
// When position/rotation/size is manually edited, break all joints, they don't apply anymore
|
||||||
if (property != "Anchored")
|
if (reset)
|
||||||
BreakJoints();
|
BreakJoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,9 @@ void PartAssembly::SetCollisionsEnabled(bool enabled) {
|
||||||
void PartAssembly::SetOrigin(CFrame newOrigin) {
|
void PartAssembly::SetOrigin(CFrame newOrigin) {
|
||||||
for (auto part : parts) {
|
for (auto part : parts) {
|
||||||
part->cframe = newOrigin * (_assemblyOrigin.Inverse() * part->cframe);
|
part->cframe = newOrigin * (_assemblyOrigin.Inverse() * part->cframe);
|
||||||
|
part->velocity = 0; // Reset velocity
|
||||||
part->UpdateProperty("CFrame");
|
part->UpdateProperty("CFrame");
|
||||||
|
part->UpdateProperty("Velocity");
|
||||||
// sendPropertyUpdatedSignal(part, "CFrame", Variant(part->cframe));
|
// sendPropertyUpdatedSignal(part, "CFrame", Variant(part->cframe));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,12 +80,15 @@ void PartAssembly::SetOrigin(CFrame newOrigin) {
|
||||||
void PartAssembly::TransformBy(CFrame transform) {
|
void PartAssembly::TransformBy(CFrame transform) {
|
||||||
for (auto part : parts) {
|
for (auto part : parts) {
|
||||||
part->cframe = transform * part->cframe;
|
part->cframe = transform * part->cframe;
|
||||||
|
part->velocity = 0; // Reset velocity
|
||||||
part->UpdateProperty("CFrame");
|
part->UpdateProperty("CFrame");
|
||||||
part->UpdateProperty("Position");
|
part->UpdateProperty("Position");
|
||||||
part->UpdateProperty("Rotation");
|
part->UpdateProperty("Rotation");
|
||||||
|
part->UpdateProperty("Velocity");
|
||||||
sendPropertyUpdatedSignal(part, "CFrame", Variant(part->cframe));
|
sendPropertyUpdatedSignal(part, "CFrame", Variant(part->cframe));
|
||||||
sendPropertyUpdatedSignal(part, "Position", Variant(part->cframe));
|
sendPropertyUpdatedSignal(part, "Position", Variant(part->cframe));
|
||||||
sendPropertyUpdatedSignal(part, "Rotation", Variant(part->cframe));
|
sendPropertyUpdatedSignal(part, "Rotation", Variant(part->cframe));
|
||||||
|
sendPropertyUpdatedSignal(part, "Velocity", Variant(part->cframe));
|
||||||
}
|
}
|
||||||
|
|
||||||
_assemblyOrigin = transform * _assemblyOrigin;
|
_assemblyOrigin = transform * _assemblyOrigin;
|
||||||
|
@ -127,6 +132,7 @@ std::vector<PartTransformState> PartAssembly::GetCurrentTransforms() {
|
||||||
t.part = part;
|
t.part = part;
|
||||||
t.cframe = part->cframe;
|
t.cframe = part->cframe;
|
||||||
t.size = part->size;
|
t.size = part->size;
|
||||||
|
t.velocity = part->velocity;
|
||||||
transforms.push_back(t);
|
transforms.push_back(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ class Selection;
|
||||||
struct PartTransformState {
|
struct PartTransformState {
|
||||||
std::shared_ptr<BasePart> part;
|
std::shared_ptr<BasePart> part;
|
||||||
Vector3 size;
|
Vector3 size;
|
||||||
|
Vector3 velocity;
|
||||||
CFrame cframe;
|
CFrame cframe;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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))))
|
if (glm::any(glm::lessThan(glm::vec3(selectionAssembly.size() + abs(draggingHandle->normal) * diff), glm::vec3(0.001f))))
|
||||||
return;
|
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.TransformBy(CFrame() + absDiff * 0.5f);
|
||||||
selectionAssembly.Scale(selectionAssembly.size() + abs(draggingHandle->normal) * diff, diff > 0);
|
selectionAssembly.Scale(selectionAssembly.size() + abs(draggingHandle->normal) * diff, diff > 0);
|
||||||
}
|
}
|
||||||
|
@ -471,6 +472,7 @@ void MainGLWidget::mouseReleaseEvent(QMouseEvent* evt) {
|
||||||
for (auto t : initialTransforms) {
|
for (auto t : initialTransforms) {
|
||||||
historyState.push_back(UndoStatePropertyChanged { t.part, "CFrame", t.cframe, t.part->cframe });
|
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, "Size", t.size, t.part->size });
|
||||||
|
historyState.push_back(UndoStatePropertyChanged { t.part, "Velocity", t.velocity, t.part->velocity });
|
||||||
}
|
}
|
||||||
|
|
||||||
M_mainWindow->undoManager.PushState(historyState);
|
M_mainWindow->undoManager.PushState(historyState);
|
||||||
|
|
Loading…
Add table
Reference in a new issue