Hi,
in my project I need to create PhysicsConstraints
and setup their angular motors during runtime in C++. Since I also need to lock certain angular motions I can’t use SLERP and have to switch to Twist and Swing. However the option to set the AngularDriveMode
of a FConstraintInstance
is deprecated in the current version and doesn’t work anymore.
There doesn’t seem to be any alternative to set the angular drive mode in C++.
This is my code where I create my constraint and set all the properties
// Set the limitations
FConstraintInstance ConstraintInstance;
ConstraintInstance.SetDisableCollision(true);
ConstraintInstance.SetLinearXLimit(ELinearConstraintMotion::LCM_Locked, 0);
ConstraintInstance.SetLinearYLimit(ELinearConstraintMotion::LCM_Locked, 0);
ConstraintInstance.SetLinearZLimit(ELinearConstraintMotion::LCM_Locked, 0);
ConstraintInstance.SetAngularSwing1Limit(EAngularConstraintMotion::ACM_Free, 0);
ConstraintInstance.SetAngularSwing2Limit(EAngularConstraintMotion::ACM_Free, 0);
ConstraintInstance.SetAngularTwistLimit(EAngularConstraintMotion::ACM_Locked, 0);
ConstraintInstance.AngularRotationOffset = FRotator(0, 0, 0);
ConstraintInstance.AngularDriveMode_DEPRECATED = EAngularDriveMode::TwistAndSwing; // Doesn't work since it's deprecated
// Create the respective joint
UPhysicsConstraintComponent* Constraint;
Constraint = NewObject<UPhysicsConstraintComponent>(RootComponent);
Constraint->RegisterComponent();
// Set the properties of the joint and connect the two meshes
Constraint->ApplyWorldOffset(FVector(0, 0, 0), false);
Constraint->ConstraintInstance = ConstraintInstance;
Constraint->AttachToComponent(myMesh, FAttachmentTransformRules(EAttachmentRule::KeepRelative, false));
Constraint->SetRelativeLocation(FVector(0.0f, 0.0f, 0.0f));
Constraint->ConstraintActor1 = this;
Constraint->ConstraintActor2 = this;
Constraint->SetAngularVelocityDrive(true, true);
Constraint->SetAngularVelocityTarget(FVector(10.0f, 10.0f, 10.0f));
Constraint->SetConstrainedComponents(parent->MeshComponent, NAME_None, myMesh, NAME_None);
The angular drive mode always stays on SLERP which I can’t use if I lock any angular motion.