Hi everyone,I got stuck with my approach to aiming down sights. I've set up my first person arms mesh to be a child of the camera. Added a socket on the right hand of the skeleton to which I attach my weapon and there is a socket in the weapon used to signal the point at which the camera should sit during aiming down sight. When the players aims holding left click what I'm trying to do is to calculate the offset of the sight socket to the root of the FPP Mesh while on the aiming down sights pose and move the camera based on that.
I'm using the code attached below.
It's Unreal Engine but the problem seemed generic enough to qualify as an algebra one. What I'm doing is obtaining the transformations from the camera to the sight bone. That gives me the sight transform relative to the camera. After that I just negate the translation vector and add it to the first child of the camera. I was expecting to have the sight bone sit at the exact same point as the camera.
What happens is that it is almost there but it's not correctly aligned. I believe my math and the general idea is right.
Any ideas why this could be failing?
Here is how I apply the resulting transform and below how I obtain it.
Thank you very much for reading.
FVector Translation = DeltaTransform.GetTranslation();
Translation.Z = 165.0f;
/*Translation.X += Translation.Y;
Translation.Y = Translation.X - Translation.Y;
Translation.X = Translation.X - Translation.Y;*/
DeltaTransform *= DefaultMesh1PTransform;
Mesh1PCamOffsetLocationDelta = DeltaTransform.GetTranslation();
Mesh1PCamOffsetRotationDelta = DeltaTransform.GetRotation();
bInterpMesh1PCamOffset = bInterp;
UE_LOG(LogTemp, Warning, TEXT("DeltaInverse Location x: %f, y: %f, z: %f"), (DeltaTransform).GetLocation().X, (DeltaTransform).GetLocation().Y, (DeltaTransform).GetLocation().Z);
Mesh1P->SetRelativeLocation(DeltaTransform.GetLocation() * -1);
UE_LOG(LogTemp, Warning, TEXT("Rotation yaw: %f, pitch: %f, roll: %f"), DeltaTransform.GetRotation().Rotator().Yaw, DeltaTransform.GetRotation().Rotator().Pitch, DeltaTransform.GetRotation().Rotator().Roll);
USkeletalMeshComponent* Mesh1P = CarryingPlayer->Mesh1P;
// Get transform to weapon attach socket space
HandToComponent *= FirearmMesh->GetSocketTransform(FName("sight_point_socket"), RTS_ParentBoneSpace);
HandToComponent *= Mesh1P->GetSocketTransform(Firearm->GetCarrySocket(), RTS_ParentBoneSpace);
// Get transform from the right hand bone relative to component (root bone)
FName CurrentBoneName = FName("hand_r");
while (CurrentBoneName != NAME_None)
ArmsADSIdleAnimSequence->GetBoneTransform(BoneTransform, Mesh1P->GetBoneIndex(CurrentBoneName), 0.0f, true);
HandToComponent *= BoneTransform;
CurrentBoneName = Mesh1P->GetParentBone(CurrentBoneName);