I solved the Problem myself.
The code I posted works. The Problem was the Mesh which I created myself in blender.
Before you export it to a .fbx you have to Apply the Scale, Rotation and Location.
I hope this will help others.
I solved the Problem myself.
The code I posted works. The Problem was the Mesh which I created myself in blender.
Before you export it to a .fbx you have to Apply the Scale, Rotation and Location.
I hope this will help others.
Hey, I want my imported Skeletal Mesh to be controlled by Angular Motors.
My Problem is, that the Skeletal Mesh did not change the orientation of the constraints.
I have a second Skeletal Mesh, which is working with this code.
I implemented it like this:
AForceSimpleHand.h
UCLASS()
class ROBCOG_API AForceSimpleHand : public ASkeletalMeshActor
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, Category = "Drive Parameters")
float Spring;
UPROPERTY(EditAnywhere, Category = "Drive Parameters")
float Damping;
UPROPERTY(EditAnywhere, Category = "Drive Parameters")
float ForceLimit;
AForceSimpleHand();
virtual void BeginPlay() override;
virtual void Tick(float DeltaSeconds) override;
private:
FConstraintInstance* LeftConstraint;
FConstraintInstance* RightConstraint;
void InitializeOrientationTwistAndSwing(FConstraintInstance* Constraint, const FQuat & Quaternion);
};
AForceSimpleHand.cpp
AForceSimpleHand::AForceSimpleHand()
{
PrimaryActorTick.bCanEverTick = true;
Spring = 50.0;
Damping = 10.0;
ForceLimit = 0.0;
USkeletalMeshComponent* SkeletalMesh = GetSkeletalMeshComponent();
if (SkeletalMesh == nullptr)
return;
SkeletalMesh->SetEnableGravity(false);
SkeletalMesh->SetSimulatePhysics(true);
}
void AForceSimpleHand::BeginPlay()
{
Super::BeginPlay();
USkeletalMeshComponent* SkeletalMesh = GetSkeletalMeshComponent();
if (SkeletalMesh != nullptr)
{
LeftConstraint = SkeletalMesh->FindConstraintInstance("Left");
if (LeftConstraint)
{
InitializeOrientationTwistAndSwing(LeftConstraint, FRotator(20, 20, 20).Quaternion());
}
RightConstraint = SkeletalMesh->FindConstraintInstance("Right");
if (RightConstraint)
{
InitializeOrientationTwistAndSwing(RightConstraint, FRotator(20, 20, 20).Quaternion());
}
}
}
void AForceSimpleHand::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
void AForceSimpleHand::InitializeOrientationTwistAndSwing(FConstraintInstance* Constraint, const FQuat & Quaternion)
{
Constraint->SetDisableCollision(true);
Constraint->SetAngularDriveMode(EAngularDriveMode::TwistAndSwing);
Constraint->SetOrientationDriveTwistAndSwing(true, true);
Constraint->SetAngularDriveParams(Spring, Damping, ForceLimit);
Constraint->SetAngularOrientationTarget(Quaternion);
}
And this is how the Constraints are defined:
I hope you can help me with that.
Thank you
Marcel