KLingo Project Documentation 1.0.0
Unreal Engine 5.6 C++ Project Documentation
로딩중...
검색중...
일치하는것 없음
AOwlPlayer.cpp
이 파일의 문서화 페이지로 가기
1// Fill out your copyright notice in the Description page of Project Settings.
2
3
4#include "AOwlPlayer.h"
5
6#include "EnhancedInputComponent.h"
7#include "EnhancedInputSubsystems.h"
9#include "Camera/CameraComponent.h"
10#include "Components/CapsuleComponent.h"
11#include "EnhancedInput/Public/InputMappingContext.h"
12#include "GameFramework/CharacterMovementComponent.h"
13#include "GameFramework/SpringArmComponent.h"
14
15
16// Sets default values
18{
19 // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
20 PrimaryActorTick.bCanEverTick = true;
21
22 // Constructor Helpers
23 ConstructorHelpers::FObjectFinder<UInputMappingContext> imcRef(TEXT("/Script/EnhancedInput.InputMappingContext'/Game/CustomContents/Input/Player/IMC_Robot.IMC_Robot'"));
24 if (imcRef.Succeeded())
25 {
26 RobotIMC = imcRef.Object;
27 }
28
29 ConstructorHelpers::FObjectFinder<UInputAction> moveActionRef(TEXT("/Script/EnhancedInput.InputAction'/Game/CustomContents/Input/Player/IA_RobotMove.IA_RobotMove'"));
30 if (moveActionRef.Succeeded())
31 {
32 MoveAction = moveActionRef.Object;
33 }
34
35 ConstructorHelpers::FObjectFinder<UInputAction> lookActionRef(TEXT("/Script/EnhancedInput.InputAction'/Game/CustomContents/Input/Player/IA_RobotLook.IA_RobotLook'"));
36 if (lookActionRef.Succeeded())
37 {
38 LookAction = lookActionRef.Object;
39 }
40
41 ConstructorHelpers::FObjectFinder<UInputAction> jumpActionRef(TEXT("/Script/EnhancedInput.InputAction'/Game/CustomContents/Input/Player/IA_RobotJump.IA_RobotJump'"));
42 if (jumpActionRef.Succeeded())
43 {
44 JumpAction = jumpActionRef.Object;
45 }
46
47 ConstructorHelpers::FObjectFinder<UInputAction> runActionRef(TEXT("/Script/EnhancedInput.InputAction'/Game/CustomContents/Input/Player/IA_RobotRun.IA_RobotRun'"));
48 if (runActionRef.Succeeded())
49 {
50 RunAction = runActionRef.Object;
51 }
52
53 ConstructorHelpers::FObjectFinder<UInputAction> interactActionRef(TEXT("/Script/EnhancedInput.InputAction'/Game/CustomContents/Input/Player/IA_RobotInteract.IA_RobotInteract'"));
54 if (interactActionRef.Succeeded())
55 {
56 InteractAction = interactActionRef.Object;
57 }
58 // ConstructorHelpers::FObjectFinder<UInputAction> grabActionRef(TEXT("/Script/EnhancedInput.InputAction'/Game/CustomContents/Input/Player/IA_RobotGrab.IA_RobotGrab'"));
59 // if (grabActionRef.Succeeded())
60 // {
61 // GrabAction = grabActionRef.Object;
62 // }
63
64 // Mesh
65 // Set Owl Mesh
66 ConstructorHelpers::FObjectFinder<USkeletalMesh> playerMeshRef(TEXT("/Script/Engine.SkeletalMesh'/Game/CustomContents/Character/Asset/Owl/SKM_GreenOwlRobot.SKM_GreenOwlRobot'"));
67 if (playerMeshRef.Succeeded())
68 {
69 GetMesh()->SetSkeletalMesh(playerMeshRef.Object);
70 GetMesh()->SetRelativeLocationAndRotation(FVector(0, 0, -70), FRotator(0, -90, 0));
71 }
72
73 // ABP
74 // Set ABP_Owl
75 ConstructorHelpers::FClassFinder<UAnimInstance> playerABPRef(TEXT("/Game/CustomContents/Animations/ABP_Owl.ABP_Owl_C"));
76 if (playerABPRef.Succeeded())
77 {
78 GetMesh()->SetAnimInstanceClass(playerABPRef.Class);
79 }
80
81 // Capsule Comp
82 GetCapsuleComponent()->InitCapsuleSize(35.f, 70.0f);
83
84 // Movement
85 bUseControllerRotationPitch = false;
86 bUseControllerRotationYaw = true;
87 bUseControllerRotationRoll = false;
88
89 GetCharacterMovement()->RotationRate = FRotator(0.0f, 500.0f, 0.0f);
90 GetCharacterMovement()->MaxWalkSpeed = WalkSpeed;
91 GetCharacterMovement()->bOrientRotationToMovement = true;
92
93 // InteractionSystem
94 InteractionSystem = CreateDefaultSubobject<UInteractionSystem>(TEXT("InteractionSystem"));
95
96 // Hold Position
97 HoldPosition = CreateDefaultSubobject<USceneComponent>(TEXT("HoldPosition"));
98 HoldPosition->SetupAttachment(GetRootComponent());
99
100 // Camera Comp
101 CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
102 CameraBoom->SetupAttachment(RootComponent);
103 CameraBoom->TargetArmLength = 250.f;
104 CameraBoom->bUsePawnControlRotation = false;
105
106 FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
107 FollowCamera->SetupAttachment(GetMesh(), TEXT("Head"));
108 // First Person Camera
109 FollowCamera->SetRelativeLocationAndRotation(FVector(0,-14.285715,21.428572), FRotator(90, 90, 0));
110 FollowCamera->bUsePawnControlRotation = true;
111}
112
114{
115 Super::BeginPlay();
116
117 auto pc = Cast<APlayerController>(Controller);
118 if (pc)
119 {
120 auto subsys = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(pc->GetLocalPlayer());
121 if (subsys)
122 {
123 subsys->AddMappingContext(RobotIMC, 0);
124 }
125 }
126}
127
128void AOwlPlayer::Tick(float DeltaTime)
129{
130 Super::Tick(DeltaTime);
131}
132
133void AOwlPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
134{
135 Super::SetupPlayerInputComponent(PlayerInputComponent);
136
137 auto playerInput = Cast<UEnhancedInputComponent>(PlayerInputComponent);
138 if (playerInput)
139 {
140 playerInput->BindAction(MoveAction, ETriggerEvent::Triggered, this, &AOwlPlayer::OnMove);
141 playerInput->BindAction(MoveAction, ETriggerEvent::Completed, this, &AOwlPlayer::OnStopMove);
142 playerInput->BindAction(LookAction, ETriggerEvent::Triggered, this, &AOwlPlayer::OnLook);
143 playerInput->BindAction(JumpAction, ETriggerEvent::Started, this, &AOwlPlayer::OnJump);
144 playerInput->BindAction(RunAction, ETriggerEvent::Started, this, &AOwlPlayer::OnRun);
145 // playerInput->BindAction(GrabAction, ETriggerEvent::Started, this, &AOwlPlayer::OnGrab);
146 // playerInput->BindAction(GrabAction, ETriggerEvent::Completed, this, &AOwlPlayer::OnGrabRelease);
147 playerInput->BindAction(InteractAction, ETriggerEvent::Started, this, &AOwlPlayer::OnInteract);
148 }
149}
150
151void AOwlPlayer::OnMove(const FInputActionValue& Value)
152{
153 // input is a Vector2D
154 FVector2D MovementVector = Value.Get<FVector2D>();
155
156 if (GetController() != nullptr)
157 {
158 // find out which way is forward
159 const FRotator Rotation = GetController()->GetControlRotation();
160 const FRotator YawRotation(0, Rotation.Yaw, 0);
161
162 // get forward vector
163 const FVector ForwardDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::X);
164
165 // get right vector
166 const FVector RightDirection = FRotationMatrix(YawRotation).GetUnitAxis(EAxis::Y);
167
168 // add movement
169 AddMovementInput(ForwardDirection, MovementVector.Y);
170 AddMovementInput(RightDirection, MovementVector.X);
171 }
172}
173
175{
176 bIsRunning = false;
177 GetCharacterMovement()->MaxWalkSpeed = WalkSpeed;
178}
179
180void AOwlPlayer::OnLook(const FInputActionValue& Value)
181{
182 // input is a Vector2D
183 FVector2D LookAxisVector = Value.Get<FVector2D>();
184
185 if (GetController() != nullptr)
186 {
187 // add yaw and pitch input to controller
188 AddControllerYawInput(LookAxisVector.X);
189 AddControllerPitchInput(LookAxisVector.Y);
190 }
191}
192
194{
195 bIsJumpStart = true;
196}
197
199{
200 if (bIsJumpStart || GetMovementComponent()->IsFalling()) return;
201
202 if (bIsRunning)
203 {
204 bIsRunning = false;
205 GetCharacterMovement()->MaxWalkSpeed = WalkSpeed;
206 }
207 else
208 {
209 bIsRunning = true;
210 GetCharacterMovement()->MaxWalkSpeed = RunSpeed;
211 }
212}
213
214// void AOwlPlayer::OnGrab(const FInputActionValue& Value)
215// {
216// // AOwlPlayer* MyPlayer = Cast<AOwlPlayer>(GetPawn());
217// // if (MyPlayer && MyPlayer->InteractionSystem)
218// // {
219// // MyPlayer->InteractionSystem->TryPickUp();
220// // }
221// InteractionSystem->TryPickUp();
222// }
223
224// void AOwlPlayer::OnGrabRelease(const FInputActionValue& Value)
225// {
226// // AOwlPlayer* MyPlayer = Cast<AOwlPlayer>(GetPawn());
227// // if (MyPlayer && MyPlayer->InteractionSystem)
228// // {
229// // MyPlayer->InteractionSystem->TryDrop();
230// // }
231// InteractionSystem->TryDrop();
232// }
233
234void AOwlPlayer::OnInteract(const FInputActionValue& Value)
235{
236 // AOwlPlayer* MyPlayer = Cast<AOwlPlayer>(GetPawn());
237 // if (MyPlayer && MyPlayer->InteractionSystem)
238 // {
239 // MyPlayer->InteractionSystem->TryInteract();
240 // }
241 InteractionSystem->TryInteract();
242}
243
245{
246 return bIsRunning;
247}
248
250{
251 return bIsJumpStart;
252}
253
255{
256 bIsJumpStart = false;
257 Jump();
258}
플레이어의 상호작용 감지 및 처리 시스템
bool GetIsJumpStart()
TObjectPtr< class UInputMappingContext > RobotIMC
Definition AOwlPlayer.h:44
virtual void Tick(float DeltaTime) override
void OnJump()
TObjectPtr< class UInputAction > RunAction
Definition AOwlPlayer.h:56
float RunSpeed
Definition AOwlPlayer.h:78
TObjectPtr< class UInputAction > MoveAction
Definition AOwlPlayer.h:47
TObjectPtr< class UInputAction > InteractAction
Definition AOwlPlayer.h:59
bool bIsRunning
Definition AOwlPlayer.h:79
TObjectPtr< class USceneComponent > HoldPosition
Definition AOwlPlayer.h:32
TObjectPtr< class USpringArmComponent > CameraBoom
Definition AOwlPlayer.h:37
bool GetIsRunning()
virtual void BeginPlay() override
bool bIsJumpStart
Definition AOwlPlayer.h:80
void OnStopMove()
TObjectPtr< class UInteractionSystem > InteractionSystem
Definition AOwlPlayer.h:28
void DoJump()
TObjectPtr< class UInputAction > JumpAction
Definition AOwlPlayer.h:53
void OnInteract(const FInputActionValue &Value)
TObjectPtr< class UInputAction > LookAction
Definition AOwlPlayer.h:50
virtual void SetupPlayerInputComponent(class UInputComponent *PlayerInputComponent) override
void OnMove(const FInputActionValue &Value)
float WalkSpeed
Definition AOwlPlayer.h:77
TObjectPtr< class UCameraComponent > FollowCamera
Definition AOwlPlayer.h:40
void OnLook(const FInputActionValue &Value)