I’ve tried to setup a system to make 2 characters holding hands with a physics simulated constraint (visually similar to what Ico does). As soon as the hands are close enough, I run the following piece of code inside a character
// Enable ragdoll for right arm
GetMesh()->SetEnableGravity(true);
GetMesh()->SetCollisionProfileName("Ragdoll");
GetMesh()->IgnoreActorWhenMoving(TheOtherCharacter, true);
GetMesh()->SetAllBodiesBelowSimulatePhysics(FName("upperarm_r"), true, true);
GetMesh()->SetAllBodiesBelowPhysicsBlendWeight(FName("upperarm_r"), 1.f);
// Create constraint
HandConstraint = NewObject<UPhysicsConstraintComponent>(this);
HandConstraint->RegisterComponent();
HandConstraint->AttachToComponent(GetMesh(), FAttachmentTransformRules::KeepWorldTransform, FName("hand_r"));
HandConstraint->SetDisableCollision(true);
HandConstraint->SetConstrainedComponents(
GetMesh(), FName("hand_r"),
TheOtherCharacter->GetMesh(), FName("hand_l")
);
HandConstraint->SetDisableCollision(true);
HandConstraint->ConstraintInstance.EnableProjection();
// Constraint configuration
HandConstraint->SetLinearXLimit(ELinearConstraintMotion::LCM_Limited, MaxDistance);
HandConstraint->SetLinearYLimit(ELinearConstraintMotion::LCM_Limited, MaxDistance);
HandConstraint->SetLinearZLimit(ELinearConstraintMotion::LCM_Limited, MaxDistance);
HandConstraint->ConstraintInstance.ProfileInstance.LinearLimit.bSoftConstraint = true;
HandConstraint->ConstraintInstance.ProfileInstance.LinearLimit.Stiffness = LinkStiffness;
HandConstraint->ConstraintInstance.ProfileInstance.LinearLimit.Damping = LinkDamping;
HandConstraint->SetAngularSwing1Limit(EAngularConstraintMotion::ACM_Limited, 45.f);
HandConstraint->SetAngularSwing2Limit(EAngularConstraintMotion::ACM_Limited, 45.f);
HandConstraint->SetAngularTwistLimit(EAngularConstraintMotion::ACM_Limited, 20.f);
I tried varying the parameters MaxDistance, LinkStiffness and LinkDamping and I tried making the right hand heavier, but the arm explodes everytime.
What parameters might be causing this? Should I make all bones heavier?