유명한 게임을 해봐라
https://namu.wiki/w/Game%20of%20the%20Year/%EB%AA%A9%EB%A1%9D
기존 ThirpersonTemplete에 LineTrace추가하기
void ATPlayer::InterActionPositive(const FInputActionValue& Value)
{
FVector _Location;
FRotator _Rotation;
FHitResult _HitOut;
//카메라중심
//GetController()->GetPlayerViewPoint(_Location, _Rotation);
//FVector _Start = _Location;
//FVector _End = (_Rotation.Vector() * 2000); //2000 -> distance
//메시중심
FVector _Start = GetActorLocation();
FVector _End = GetActorLocation() + (GetActorForwardVector() * interactionDistance);
FCollisionQueryParams _TraceParams;
GetWorld()->LineTraceSingleByChannel(_HitOut, _Start, _End, ECC_Visibility, _TraceParams);
DrawDebugLine(GetWorld(), _Start, _End, FColor::Magenta, false, 3.f);
}
맵변경
AnitiAliasing을 끄거나 Unlit를 끄면 성능이 가벼워진다.
TriggerBox delegation작성
UFUNCTION()
void OnComponentBeginOverlapTB(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);
ANPC::ANPC()
{
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
cameraComp = CreateDefaultSubobject<UCameraComponent>(TEXT("CameraComp"));
cameraComp->SetupAttachment(RootComponent);
cameraComp->bUsePawnControlRotation = false;
triggerBox = CreateDefaultSubobject<UBoxComponent>(TEXT("TriggerBox"));
triggerBox->SetupAttachment(RootComponent);
triggerBox->OnComponentBeginOverlap.AddDynamic(this, &ANPC::OnComponentBeginOverlapTB);
}
void ANPC::OnComponentBeginOverlapTB(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("debug"));
}
게임모드에서 디폴트맵으로 가든을 설정하고 BP_NPC를 디폴트폰으로 설정한다.
프리뷰카메라가 이정도 나오게 완성한다.
카메라를 배치한다.
void ANPC::OnComponentBeginOverlapTB(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Yellow, TEXT("debug"));
APlayerController* MyPlayerController = UGameplayStatics::GetPlayerController(this, 0);
MyPlayerController->SetViewTarget(this);
MyPlayerController->SetInputMode(FInputModeUIOnly()); // UI만 인풋된다.
MyPlayerController->SetShowMouseCursor(true);
}
NPC.cpp
NPC.h
NPC에서 WBP_ITEM을 연결해준다.
이제 Exit에 기능을 연결한다. isVariable을 체크한다.
위젯을 지워주고 마우스를 없애주고 ViewPort로 부터 디태치해준다.
실행해보니가 Exit를 눌러도 Widget이 지워지지 않아 따로 TestPlayer를 만들어 실험해 보니 Wdiget은 문제 없다.
'언리얼수업 > 언리얼' 카테고리의 다른 글
NPC 배회기능 적추적기능 C++ (0) | 2023.11.28 |
---|---|
231127 DrawDebugSphere() and HitResult (0) | 2023.11.28 |
231125 205 특강 (2) | 2023.11.25 |
231123 Widget in Actor C++ (0) | 2023.11.24 |
211124 LineTrace C++ (1) | 2023.11.24 |