2๊ฐ ์บ๋ฆญํฐ์ ์
๋ ฅ์์คํ
: compile error๋ก ์ธํด ์ฝ๋๋ฅผ ์ ์ฉํ ์ ์์ต๋๋ค.
10000์ ์ ํ์ผ๋ก ์ธํด์ ๋ต๊ธ๋ก ์ฝ๋๋ฅผ ์ฌ๋ฆฝ๋๋ค.์๋๊ฐ ์ ๊ฐ ์์ฑํ ABCharacter.cpp ํ์ผ์
๋๋ค.// Fill out your copyright notice in the Description page of Project Settings. #include "Character/ABCharacterPlayer.h" #include "Camera/CameraComponent.h" #include "GameFramework/SpringArmComponent.h" #include "InputMappingContext.h" #include "EnhancedInputComponent.h" #include "EnhancedInputSubsystems.h" AABCharacterPlayer::AABCharacterPlayer() { // Camera CameraBoom = CreateDefaultSubobject(TEXT("CameraBoom")); CameraBoom->SetupAttachment(RootComponent); CameraBoom->TargetArmLength = 400.0f; CameraBoom->bUsePawnControlRotation = true; FollowCamera = CreateDefaultSubobject(TEXT("FollowCamera")); FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // springArm์ ์๋์ผ๋ก ๋ฌ๋ผ๋ถ๋๋ค. FollowCamera->bUsePawnControlRotation = false; // Input static ConstructorHelpers::FObjectFinder InputMappingContextRef(TEXT("/Script/EnhancedInput.InputMappingContext'/Game/ArenaBattle/Input/IMC_Default.IMC_Default'")); if (InputMappingContextRef.Object != nullptr) { DefaultMappingContext = InputMappingContextRef.Object; } static ConstructorHelpers::FObjectFinder InputActionMoveRef(TEXT("/Script/EnhancedInput.InputAction'/Game/ArenaBattle/Input/Actions/IA_Move.IA_Move'")); if (InputActionMoveRef.Object != nullptr) { MoveAction = InputActionMoveRef.Object; } static ConstructorHelpers::FObjectFinder InputActionJumpRef(TEXT("/Script/EnhancedInput.InputAction'/Game/ArenaBattle/Input/Actions/IA_Jump.IA_Jump'")); if (InputActionJumpRef.Object != nullptr) { JumpAction = InputActionJumpRef.Object; } static ConstructorHelpers::FObjectFinder InputActionLookRef(TEXT("/Script/EnhancedInput.InputAction'/Game/ArenaBattle/Input/Actions/IA_Look.IA_Look'")); if (InputActionLookRef.Object != nullptr) { LookAction = InputActionLookRef.Object; } } void AABCharacterPlayer::BeginPlay() { Super::BeginPlay(); APlayerController* PlayerController = CastChecked(GetController()); if (UEnhancedInputLocalPlayerSubsystem* Subsystem = ULocalPlayer::GetSubsystem(PlayerController)) { // mapping context ์ถ๊ฐ Subsystem->AddMappingContext(DefaultMappingContext, 0); // ์ฐ์ ์์๋ฅผ ์ง์ ํด์ ๋ค์ํ input์ด ์๋ก ๊ฒน์น ๋ ์ฐ์ ์์๊ฐ ๋์ ์
๋ ฅ์ ๋จผ์ ์ฒ๋ฆฌ // ๋ฐํ์์์ ํด๋น ํจ์๋ฅผ ์ด์ฉํด์ ๋บ ์ ์๋ค. // Subsystem->RemoveMappingContext(DefaultMappingContext); } } void AABCharacterPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) { Super::SetupPlayerInputComponent(PlayerInputComponent); // ๋ฐ๋์ Enhance Input System์ ์ฐ๋๋ก ์ธํ
// CastChecked๋ฅผ ํตํด ํด๋น input system์ ์ฐ์ง ์์ผ๋ฉด ์๋ฌ๋ฅผ ๋ฐ์์ํจ๋ค. UEnhancedInputComponent* EnhancedInputComponent = CastChecked(PlayerInputComponent); // ์์ฑ์์์ ๋ง๋ Action์ ํจ์์ binding ํ๋ค. // Jump์ StopJumping๋ Character๊ฐ ์ ๊ณตํ๋ ํจ์ API์ด๋ค. EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::Jump); EnhancedInputComponent->BindAction(JumpAction, ETriggerEvent::Triggered, this, &ACharacter::StopJumping); EnhancedInputComponent->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AABCharacterPlayer::Move); EnhancedInputComponent->BindAction(LookAction, ETriggerEvent::Triggered, this, &AABCharacterPlayer::Look); } void AABCharacterPlayer::Move(const FInputActionValue& Value) // Value์ xy ๊ฐ์ ๊ฐ์ ธ์จ๋ค. { FVector2D MovementVector = Value.Get(); const FRotater Rotation = Controller->GetControlRotation(); const FRotater YawRotation(0, Rotation.Yaw, 0); const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X); const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y); // Value์์ ๊ฐ์ ธ์จ x, y ๊ฐ์ Movement Component์ ์ฐ๊ฒฐํ๋ค. AddMovementInput(ForwardDirection, MovementVector.X); AddMovementInput(RightDirection, MovementVector.Y); } void AABCharacterPlayer::Look(const FInputActionValue& Value) { FVector2D LookAxisVector = Value.Get(); // controller์ ํ์ ์ค์ ์ผ๋ก ์นด๋ฉ๋ผ์ springArm์ด ํด๋น component๋ฅผ ๋ฐ๋ผ๋ณด๋๋ก ์ค์ AddControllerYawInput(LookAxisVector.X); AddControllerYawInput(LookAxisVector.Y); }