fix(physics): motor6d crashes

This commit is contained in:
maelstrom 2025-09-06 20:21:56 +02:00
parent c8be848cea
commit 28f416bf63
3 changed files with 7 additions and 19 deletions

View file

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

View file

@ -5,8 +5,6 @@
#include "objects/joint/jointinstance.h"
#include <memory>
#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<Motor6D> New() { return std::make_shared<Motor6D>(); };
static inline std::shared_ptr<Instance> Create() { return std::make_shared<Motor6D>(); };
};
#undef DEF_PROP_PHYS
};

View file

@ -306,7 +306,7 @@ void BasePart::MakeJoints() {
}
void BasePart::UpdateNoBreakJoints() {
if (workspace())
if (workspace() != nullptr)
workspace()->SyncPartPhysics(std::dynamic_pointer_cast<BasePart>(this->shared_from_this()));
}