목차

     

     


     

     

    Crosshair


     

     

    MainPlayerController 

     

    새 C++ 클래스 - PlayerController - MainPlayerController 생성

     

    BP_PlayerController

     

     

     

     

     

     

     

     

     

     

     


     

     

    MainHUD

     

    새 C++ 클래스 - HUD - MainHUD 생성

     

     

     

    BP_MainHUD

     


     

     

    BP_MultiplayerGameMode 설정

     


     

     

     

     

     

     

     

    Crosshair 방향과 Muzzle 방향 일치시키기

     


     

     

    문제상황

     

    문제상황

    Crosshair가 가르키는 방향과 Muzzle이 가르키는 방향이 다르다. 

    FTransform MuzzleTipTransform = EquippedWeapon->GetWeaponMesh()->GetSocketTransform(FName("MuzzleFlash"), ERelativeTransformSpace::RTS_World);
    FVector MuzzleX(FRotationMatrix(MuzzleTipTransform.GetRotation().Rotator()).GetUnitAxis(EAxis::X));
    DrawDebugLine(GetWorld(), MuzzleTipTransform.GetLocation(), MuzzleTipTransform.GetLocation() + MuzzleX * 1000.0f, FColor::Blue);
    DrawDebugLine(GetWorld(), MuzzleTipTransform.GetLocation(), BaseCharacter->GetHitTarget(), FColor::Red);


     

     

    해결방안

     

    오른손의 회전(RightHandRotation)을 적용한다.

    FTransform RightHandTransform = EquippedWeapon->GetWeaponMesh()->GetSocketTransform(FName("Hand_R"), ERelativeTransformSpace::RTS_World); // 오른손 소켓의 회전, 비율, 위치값을 담아준다.
    RightHandRotation = UKismetMathLibrary::FindLookAtRotation(RightHandTransform.GetLocation(), RightHandTransform.GetLocation() + (RightHandTransform.GetLocation() - BaseCharacter->GetHitTarget()));
    
    FTransform MuzzleTipTransform = EquippedWeapon->GetWeaponMesh()->GetSocketTransform(FName("MuzzleFlash"), ERelativeTransformSpace::RTS_World);
    FVector MuzzleX(FRotationMatrix(MuzzleTipTransform.GetRotation().Rotator()).GetUnitAxis(EAxis::X));
    DrawDebugLine(GetWorld(), MuzzleTipTransform.GetLocation(), MuzzleTipTransform.GetLocation() + MuzzleX * 1000.0f, FColor::Blue);
    DrawDebugLine(GetWorld(), MuzzleTipTransform.GetLocation(), BaseCharacter->GetHitTarget(), FColor::Red);

     

    오른손의 회전값을 구한다.

    • 오른손(hand_r)에서 충돌지점(HitTarget)으로 향하는 벡터의 회전값을 구한다.

    시작 위치 벡터(=오른손 위치):  RightHandTransform.GetLocation() 

    충돌 지점을 향하는 벡터:  RightHandTransform.GetLocation() + (RightHandTransform.GetLocation() - BaseCharacter->GetHitTarget())

     

    시작위치를 맞춰야 하므로 시작위치 +  (RightHandTransform.GetLocation() - BaseCharacter->GetHitTarget())

     

     

     

     

     

    Animation Blueprint

    Transform Bone 적용 후에 FABRIK를 적용한다. 

     

     

     

    일치시켜준 후 모습