PoseableMeshComponent and Bone Rotation

Ok,

i replaced the SkeletalMeshComponent with a PoseableMeshComponent. Now i got better access to bone rotation.

But somehow everything is upside down. The Barrel moves down when Pitch is positiv.

auto BarrelRotation = Turret->GetBoneRotationByName(FName("barrel"), EBoneSpaces::ComponentSpace);

auto AimAsRotator = AimDirection.Rotation();
auto DeltaRotator = AimAsRotator.Pitch - BarrelRotation.Roll;
// Cap the RelativeSpeed to prevent strange behavior
auto DeltaRoll = FMath::Clamp<float>(DeltaRotator, -1, 1);

auto EleveationChange = DeltaRoll * MaxDegreesPerSecondBa * GetWorld()->DeltaTimeSeconds;

auto RawNewElevation = Turret->GetBoneRotationByName(FName("barrel"), EBoneSpaces::ComponentSpace).Roll + EleveationChange;

auto Elevation = FMath::Clamp<float>(RawNewElevation, 0, 40);
Turret->SetBoneRotationByName(FName("barrel"), FRotator(0, -90, Elevation), EBoneSpaces::ComponentSpace);

The Problem in this snippet is that it prevents itself from rotating in negative values. Changing Elevation Clamp to -40, 0 didn’t help.

Here another thing:

auto DeltaRotator = AimAsRotator.Pitch - BarrelRotation.Roll;

Why is the BarrelRotation.Roll the Pitch value in AimAsRotator?

Hey there, can you send a screenshot of the game to better visualize what you are trying to do?

I fixed the issue. Just a tiny change was missing…

auto BarrelRotation = Turret->GetBoneRotationByName(FName("barrel"), EBoneSpaces::ComponentSpace);

auto AimAsRotator = AimDirection.Rotation().Pitch;
auto DeltaRotator = AimAsRotator + BarrelRotation.Roll;

// Cap the RelativeSpeed to prevent strange behavior
auto DeltaRoll = FMath::Clamp<float>(DeltaRotator, -1, 1);

auto EleveationChange = DeltaRoll * MaxDegreesPerSecondBa * GetWorld()->DeltaTimeSeconds;

auto RawNewElevation = Turret->GetBoneRotationByName(FName("barrel"), EBoneSpaces::ComponentSpace).Roll - EleveationChange;

auto Elevation = FMath::Clamp<float>(RawNewElevation, -40, 0);

Turret->SetBoneRotationByName(FName("barrel"), FRotator(0, -90, Elevation), EBoneSpaces::ComponentSpace);