In the latest version of Unreal Engine 4.4, the Physicsconstraint in Blueprint is Bug-Blueprint cannot edit constraint's two actor components, and the only way to do this is through C + + code. There are many such questions, fortunately, the source code to you, and how to change with their own.
I want to implement the role swing function in the Thirdperson template, just like the Persian monkeys.
First, add a uphysicsconstraintcomponent to character blueprint:
Uproperty (visibledefaultsonly, Category = "Nanconstraint")
Tsubobjectptr<class uphysicsconstraintcomponent> Constraintcomp;
Also need a fixed physical object when tying a string of pegs, so add another uspherecomponent:
Uproperty (visibledefaultsonly, Category = "Nanconstraint")
Tsubobjectptr<class uspherecomponent> Blocksphere;
Initialize them in the character constructor:
Create constraint Component
Constraintcomp = Pcip. Createdefaultsubobject<uphysicsconstraintcomponent> (This, TEXT ("Constraintcomp"));
Fconstraintinstance Constraintinst;
Constraintcomp->constraintinstance = Constraintinst;
Blocksphere = Pcip. Createdefaultsubobject<uspherecomponent> (This, TEXT ("blockcomponent"));
Define two methods Swing () and unswing (), one start constraint, one disconnect constraint
void Ananprojectcharacter::swing ()
{
Fvector charlocation = Getactorlocation ();
Fvector spherelocation = charlocation + fvector (0, 0, Constraintlen);
Capsulerot = Capsulecomponent->getcomponentrotation ();
Blocksphere->setworldlocation (spherelocation);
Capsulecomponent->setsimulatephysics (TRUE);
Constraintcomp->setworldlocation (spherelocation);
Constraintcomp->setconstrainedcomponents (Blocksphere, Name_none, Capsulecomponent, NAME_None);
}
void Ananprojectcharacter::unswing ()
{
Capsulecomponent->setsimulatephysics (FALSE);
Constraintcomp->breakconstraint ();
Capsulecomponent->setworldrotation (Capsulerot);
}
It is important to note that character's capsulecomponent itself is not enabled for physical simulations, and in order for him to be put up, he needs to be added to the physical simulation after enabling constraint. Of course, when you disconnect, don't forget to disable it again. Capsulerot save before enabling physical simulation, capsulecomponent rotation, if not fixed, the role of constraint after the disconnection is likely to be head-down, very happy feeling.
Unreal Engine 4 C + + code dynamically created constraint