From 28f416bf6399455c38995eae69d1f5db6f5e7d79 Mon Sep 17 00:00:00 2001 From: maelstrom Date: Sat, 6 Sep 2025 20:21:56 +0200 Subject: [PATCH] fix(physics): motor6d crashes --- core/src/objects/joint/motor6d.cpp | 12 ++---------- core/src/objects/joint/motor6d.h | 12 ++++-------- core/src/objects/part/basepart.cpp | 2 +- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/core/src/objects/joint/motor6d.cpp b/core/src/objects/joint/motor6d.cpp index 14ceaa3..64bf926 100644 --- a/core/src/objects/joint/motor6d.cpp +++ b/core/src/objects/joint/motor6d.cpp @@ -27,14 +27,6 @@ void Motor6D::buildJoint() { jointWorkspace = workspace; } -void Motor6D::onUpdated(std::string property) { - if (property == "DesiredAngle") { - joint.setTargetAngle(desiredAngle); - } else if (property == "MaxVelocity") { - joint.setAngularVelocity(maxVelocity); - } -} - bool Motor6D::isDrivenJoint() { return true; } @@ -59,7 +51,7 @@ void Motor6D::OnPhysicsStep(float deltaTime) { CFrame newFrame = rotatedAnchor * c1.Inverse(); part1.lock()->cframe = newFrame; - jointWorkspace.lock()->SetPhysicalCFrameInternal(part1.lock(), newFrame); + part1.lock()->UpdateNoBreakJoints(); } else if (!part0.lock()->anchored) { CFrame anchorPoint = part1.lock()->cframe * c1; Vector3 angles = anchorPoint.ToEulerAnglesXYZ(); @@ -67,6 +59,6 @@ void Motor6D::OnPhysicsStep(float deltaTime) { CFrame newFrame = rotatedAnchor * c0.Inverse(); part0.lock()->cframe = newFrame; - jointWorkspace.lock()->SetPhysicalCFrameInternal(part0.lock(), newFrame); + part0.lock()->UpdateNoBreakJoints(); } } \ No newline at end of file diff --git a/core/src/objects/joint/motor6d.h b/core/src/objects/joint/motor6d.h index 0d2f8b6..185f29b 100644 --- a/core/src/objects/joint/motor6d.h +++ b/core/src/objects/joint/motor6d.h @@ -5,8 +5,6 @@ #include "objects/joint/jointinstance.h" #include -#define DEF_PROP_PHYS DEF_PROP_(on_update=onUpdated) - class DEF_INST Motor6D : public JointInstance { AUTOGEN_PREAMBLE @@ -19,12 +17,10 @@ public: Motor6D(); ~Motor6D(); - DEF_PROP float currentAngle; - DEF_PROP_PHYS float desiredAngle; - DEF_PROP_PHYS float maxVelocity; + DEF_PROP float currentAngle = 0; + DEF_PROP float desiredAngle = 0; + DEF_PROP float maxVelocity = 0.1; static inline std::shared_ptr New() { return std::make_shared(); }; static inline std::shared_ptr Create() { return std::make_shared(); }; -}; - -#undef DEF_PROP_PHYS \ No newline at end of file +}; \ No newline at end of file diff --git a/core/src/objects/part/basepart.cpp b/core/src/objects/part/basepart.cpp index 13c3ecb..33e2336 100644 --- a/core/src/objects/part/basepart.cpp +++ b/core/src/objects/part/basepart.cpp @@ -306,7 +306,7 @@ void BasePart::MakeJoints() { } void BasePart::UpdateNoBreakJoints() { - if (workspace()) + if (workspace() != nullptr) workspace()->SyncPartPhysics(std::dynamic_pointer_cast(this->shared_from_this())); }