Setup angular motors in c++

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.

117874-angulardrivemode.png

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.

117875-angularmotor.png

Hello ASchoenfeld,

After doing a bit of digging I was able to find that this variable has been deprecated without documentation. I have written up a report and I have submitted it to the developers for further consideration. I have also provided a link to the public tracker. Please feel free to use the link provided for future updates.

Link: Unreal Engine Issues and Bug Tracker (UE-39516)

Make it a great day

It appears a lot of this functionality got split up into other files.

This is how I got it to work…

ConstraintInstance.ProfileInstance.AngularDrive.AngularDriveMode = EAngularDriveMode::TwistAndSwing;

This is exactly what I was looking for. Thank you very much.