I’m working on the following.
I want to rotate the character’s upper body in the aiming direction at all times. (Like a picture)
It doesn’t matter when shooting quietly, but if I move sideways and shoot, it becomes like below.
Therefore, I tried to find the angle like the code below.
float UPlayerAnim::GetAimRotate(ATPSPlayer* Player)
{
// 조준점의 위치 Position of the aiming point
FVector CamToAim = Player->CameraComp->GetComponentLocation() + Player->CameraComp->GetForwardVector() * 15000;
// 소켓 회전으로부터 forwardvector 구하기 Get forwardvector value from socket rotation
FRotator Rot = Player->GunMesh->GetSocketRotation(FName(TEXT("FirePosition")));
Rot.Pitch = 0; Rot.Roll = 0;
FVector FireSocketPos = UKismetMathLibrary::GetForwardVector(Rot);
FireSocketPos.Z = 0;
// 총구 -> 에임 벡터 Vector from firesocket to aiming direction
FVector GunToAim = CamToAim - Player->GunMesh->GetSocketLocation(FName(TEXT("FirePosition")));;
GunToAim.Z = 0;
// 총구 -> 에임방향 내적 DotProduct
float Dot = FVector::DotProduct(FireSocketPos.GetSafeNormal(), GunToAim.GetSafeNormal());
// 아크 코사인을 통해 두 각도 구함 Find the angle between the two vectors through the arc cosine
float AcosAngle = FMath::Acos(Dot);
return FMath::RadiansToDegrees(AcosAngle);
}
And I set it up in the Anim graph. (AimRotate)
Then jittering occurs, and when I shoot while moving sideways, my body bends back.
Did I get the wrong angle between the two vectors?
My brain is stupid, so I used a translator and I’m not good at math.
Help me.