fix(physics): motor6d relies on constraints
This commit is contained in:
parent
2a62884993
commit
73c5bc5a26
2 changed files with 8 additions and 20 deletions
|
@ -44,21 +44,6 @@ void Motor6D::OnPhysicsStep(float deltaTime) {
|
||||||
// Shouldn't in theory be necessary, but just in case.
|
// Shouldn't in theory be necessary, but just in case.
|
||||||
if (part0.expired() || part1.expired()) return;
|
if (part0.expired() || part1.expired()) return;
|
||||||
|
|
||||||
if (!part1.lock()->anchored) {
|
// TODO: Re-add rotating only one part when both are unanchored, maybe?
|
||||||
CFrame anchorPoint = part0.lock()->cframe * c0;
|
joint.setTargetAngle(currentAngle);
|
||||||
Vector3 angles = anchorPoint.ToEulerAnglesXYZ();
|
|
||||||
CFrame rotatedAnchor = CFrame::FromEulerAnglesXYZ({angles.X(), angles.Y(), currentAngle}) + anchorPoint.Position();
|
|
||||||
CFrame newFrame = rotatedAnchor * c1.Inverse();
|
|
||||||
|
|
||||||
part1.lock()->cframe = newFrame;
|
|
||||||
part1.lock()->UpdateNoBreakJoints();
|
|
||||||
} else if (!part0.lock()->anchored) {
|
|
||||||
CFrame anchorPoint = part1.lock()->cframe * c1;
|
|
||||||
Vector3 angles = anchorPoint.ToEulerAnglesXYZ();
|
|
||||||
CFrame rotatedAnchor = CFrame::FromEulerAnglesXYZ({angles.X(), angles.Y(), currentAngle}) + anchorPoint.Position();
|
|
||||||
CFrame newFrame = rotatedAnchor * c0.Inverse();
|
|
||||||
|
|
||||||
part0.lock()->cframe = newFrame;
|
|
||||||
part0.lock()->UpdateNoBreakJoints();
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -234,14 +234,17 @@ PhysJoint PhysWorld::createJoint(PhysJointInfo& type, std::shared_ptr<BasePart>
|
||||||
settings.mPoint2 = convert<JPH::Vec3>(info->c1.Position());
|
settings.mPoint2 = convert<JPH::Vec3>(info->c1.Position());
|
||||||
settings.mNormalAxis2 = convert<JPH::Vec3>(info->c1.RightVector());
|
settings.mNormalAxis2 = convert<JPH::Vec3>(info->c1.RightVector());
|
||||||
settings.mHingeAxis2 = convert<JPH::Vec3>(info->c1.LookVector());
|
settings.mHingeAxis2 = convert<JPH::Vec3>(info->c1.LookVector());
|
||||||
|
|
||||||
|
// settings for Motor6D
|
||||||
|
settings.mMotorSettings.mSpringSettings.mFrequency = 20;
|
||||||
|
settings.mMotorSettings.mSpringSettings.mDamping = 1;
|
||||||
constraint = settings.Create(*part0->rigidBody.bodyImpl, *part1->rigidBody.bodyImpl);
|
constraint = settings.Create(*part0->rigidBody.bodyImpl, *part1->rigidBody.bodyImpl);
|
||||||
|
|
||||||
if (PhysMotorizedJointInfo* info = dynamic_cast<PhysMotorizedJointInfo*>(&type)) {
|
if (PhysMotorizedJointInfo* info = dynamic_cast<PhysMotorizedJointInfo*>(&type)) {
|
||||||
static_cast<JPH::HingeConstraint*>(constraint)->SetMotorState(JPH::EMotorState::Velocity);
|
static_cast<JPH::HingeConstraint*>(constraint)->SetMotorState(JPH::EMotorState::Velocity);
|
||||||
static_cast<JPH::HingeConstraint*>(constraint)->SetTargetAngularVelocity(-info->initialVelocity);
|
static_cast<JPH::HingeConstraint*>(constraint)->SetTargetAngularVelocity(-info->initialVelocity);
|
||||||
} else if (PhysStepperJointInfo* info = dynamic_cast<PhysStepperJointInfo*>(&type)) {
|
} else if (PhysStepperJointInfo* _ = dynamic_cast<PhysStepperJointInfo*>(&type)) {
|
||||||
static_cast<JPH::HingeConstraint*>(constraint)->SetMotorState(JPH::EMotorState::Velocity);
|
static_cast<JPH::HingeConstraint*>(constraint)->SetMotorState(JPH::EMotorState::Position);
|
||||||
static_cast<JPH::HingeConstraint*>(constraint)->SetTargetAngularVelocity(0);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
panic();
|
panic();
|
||||||
|
|
Loading…
Add table
Reference in a new issue