Unreal - 캐릭터 회전

2025. 10. 19. 01:17·Unreal 프로젝트 다이어리/두번째 프로젝트

 

캐릭터를 회전시킬때 마우스를 회전하면 캐릭터는 가만있고 카메라만 회전해야하는데

지금은 캐릭터도 같이회전해버린다 수정해보자

 

현재 컨트롤러에 바인드된 카메라제어는 이와같다

Axis축에 따라 Yaw인풋을 변경하고있다

InputComponent->BindAxis("MouseX", this, &AMainCharacterController::TurnCamera);

void AMainCharacterController::TurnCamera(float axisValue)
{
	AddYawInput(axisValue * mouseSensitivity);
}

 

캐릭터의 생성자 코드를 수정

AMainCharacter::AMainCharacter()
{
	PrimaryActorTick.bCanEverTick = true;
	SetRootComponent(GetCapsuleComponent());
	GetMesh()->SetRelativeLocation(FVector(0.f, 0.f, -90.f));
	GetMesh()->SetRelativeRotation(FRotator(0.f, -90.f, 0.f));
	//Character Settings
	ConstructorHelpers::FObjectFinder<USkeletalMesh> mainCharAsset
	(TEXT("/Game/MainCharacter/SKM_MainCharacter.SKM_MainCharacter"));
	if (mainCharAsset.Succeeded())
	{
		GetMesh()->SetSkeletalMesh(mainCharAsset.Object);
	}

	cameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("MainCameraBoom"));
	cameraBoom->SetupAttachment(RootComponent);

	//view settings (BackView, thirdPerson)
	cameraBoom->TargetArmLength = 400.f;
	cameraBoom->SetRelativeRotation(FRotator(0.f));
	cameraBoom->bEnableCameraLag = true;
	cameraBoom->CameraLagSpeed = 15.f;
    
    cameraBoom->bUsePawnControlRotation = true;
    cameraBoom->bInheritPitch = false;
    cameraBoom->bInheritYaw = true;
    cameraBoom->bInheritRoll = false;

	//camera hit handling
	cameraBoom->bDoCollisionTest = true;

	mainCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("MainCamera"));
	mainCamera->SetupAttachment(cameraBoom);
	mainCamera->SetRelativeLocation(FVector(33.f, 0.f, 180.f));
	mainCamera->SetRelativeRotation(FRotator(-17.5f, 0.f, 0.f));
	mainCamera->bUsePawnControlRotation = false;

	//camera mouse handling
	bUseControllerRotationYaw = false;
	bUseControllerRotationPitch = false;
	bUseControllerRotationRoll = false;

    GetCharacterMovement()->bOrientRotationToMovement = true;
    GetCharacterMovement()->bUseControllerDesiredRotation = true;
    GetCharacterMovement()->RotationRate = FRotator(0.f, 540.f, 0.f);
	
	//jump handling
	GetCharacterMovement()->JumpZVelocity = 600.f;
 }

 

해당 옵션을 코드로 켜주면 된다

 

컨트롤러의 각도를 초기 설정해주는 함수를 만들고 beginplay에서 적용

void AMainCharacterController::InitialSetting()
{
	APawn* myPawn = GetPawn();
	if (!myPawn) return;
	//controller rotation
	FRotator startRot = myPawn->GetActorRotation();
	startRot.Pitch = 0.f; // 위로 보는 각도 초기화
	startRot.Roll = 0.f;
	SetControlRotation(startRot);
	AMainCharacter* mainCharacter = Cast<AMainCharacter>(myPawn);
	if (mainCharacter && mainCharacter->cameraBoom)
	{
		mainCharacter->cameraBoom->SetWorldRotation(FRotator(0.f, startRot.Yaw, 0.f));
	}
}

 

'Unreal 프로젝트 다이어리 > 두번째 프로젝트' 카테고리의 다른 글

Unreal - 파쿠르 방해물 탐색  (0) 2025.10.29
Unreal - 적 타게팅  (0) 2025.10.29
Unreal - Posture Progress / Hit Direction  (0) 2025.08.29
Unreal - HitInterface 상호작용  (0) 2025.08.23
Unreal - Hash 기반 AI/Enemy 데이터 설계하기  (0) 2025.08.23
'Unreal 프로젝트 다이어리/두번째 프로젝트' 카테고리의 다른 글
  • Unreal - 파쿠르 방해물 탐색
  • Unreal - 적 타게팅
  • Unreal - Posture Progress / Hit Direction
  • Unreal - HitInterface 상호작용
lucodev
lucodev
커피와 노트북 그리고 개발
  • lucodev
    루코 개발테이블
    lucodev
  • 전체
    오늘
    어제
    • 분류 전체보기 (210) N
      • Unreal 프로젝트 다이어리 (107) N
        • 첫번째 프로젝트 (73)
        • 두번째 프로젝트 (34) N
      • Unreal 팁 (8)
      • Unreal 디버깅 (8)
      • C++ 프로그래머스 (52)
        • Stack,Queue (7)
        • Hash (4)
        • Heap (2)
        • Sort (5)
        • Exhaustive search (5)
        • Greedy (2)
        • BFS , DFS (7)
        • Graph (2)
        • Dynamic Programming (1)
        • C++ Math (2)
        • 기타 문제 (14)
      • C++ 백준 (4)
      • C++ 팁 (1)
      • 개인 코테 & 스타디 <비공개> (29)
        • 코드 개인보관함 (9)
        • 코딩테스트+@ (11)
        • 알고리즘 스타디 (6)
        • 알고리즘 스타디 과제 (3)
        • 비공개 (0)
  • 인기 글

  • 최근 글

  • 최근 댓글

  • 링크

  • 공지사항

  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 태그

    언리얼 파쿠르
    언리얼 ui
    unreal inventory
    언리얼 컷씬
    unreal 모션매칭
    unreal 파쿠르
    언리얼 시퀀스
    Unreal Parkour
    unreal 시퀀스
    언리얼 behaviortree
    언리얼 모션매칭
    언리얼 프로그래스바
    언리얼 인벤토리
    언리얼 motionmatching
    언리얼 parkour
    언리얼 behavior tree
    언리얼 상호작용
    unreal 인벤토리
    언리얼
    언리얼 비헤이비어트리
  • hELLO· Designed By정상우.v4.10.3
lucodev
Unreal - 캐릭터 회전
상단으로

티스토리툴바