화면 밖으로 나간 총알과 에너미를 제거하기 위해 킬존액터를 만들어 보겠습니다. 플레이어가 바닥으로 내려가지 못하게도 해보겠습니다.
먼저 프로젝트 세팅에서 Collision Category에서 프리셋을 KillZone으로 만듭니다. 채널은 만들지 않고 ObjectType을 WorldStatic으로 합니다. Enemy와 Bullet은 Overlap 으로 충돌을 감지하고 Player는 Block으로 충돌시 못움직이게 합니다.
Enemy와 Bullet 프리셋도 열어 WorldStatic와 overlap되게 체크해 줍니다.



KillZone C++ Class를 언리얼에디터에서 만들고 visual studio로 가서
HEAD에 충돌을 감지할 박스컴포넌트 변수를 만들고
UPROPERTY(EditAnywhere)
class UBoxComponent* boxComp;
KillZone.cpp에서 UBoxComponent를 만들어 연결해줍니다. 충돌만 감지하므로 Mesh를 만들 필요는 없습니다.
KillZone Collision Preset을 연결해 줍니다.
#include "KillZone.h"
#include "Components/BoxComponent.h"
// Sets default values
AKillZone::AKillZone()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
boxComp = CreateDefaultSubobject<UBoxComponent>(TEXT("BoxCollider"));
SetRootComponent(boxComp);
boxComp->SetMobility(EComponentMobility::Static);
boxComp->SetBoxExtent(FVector(50, 2000, 50));
boxComp->SetCollisionProfileName(TEXT("KillZone"));
}
PlayerPawn.cpp로 이동 생성자 맨아래 충돌처리를 해줘 KillZone과 부딪치게 합니다.
boxComp->SetCollisionResponseToChannel(ECC_WorldStatic, ECR_Block);
언리얼 에디터로가 KillZone 을 부모로 BP_KillZone 블루프린터를 작성하고 화면 위아래로 배치합니다. 테스트를 위해 잘 보이게 합니다.
플레이해보면 아직 플레이어폰이 킬존과 블록되지 않습니다. 플레이어폰이 이동하는 방식이 물리적이지 않고 SetLocation()을 이용한 위치이동방식이라서 그렇습니다. 2번째 파라미터 true를 추가해서 충돌을 감지할수 있습니다. PlayerPawn.cpp의 Tick()함수 맨아래 SetActorLocation()을 수정합니다.
void APlayerPawn::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
//Make direction and updata Actor location
FVector dir = FVector(0, h, v);
dir.Normalize();
FVector newLocation = GetActorLocation() + dir * moveSpeed * DeltaTime;
SetActorLocation(newLocation, true);
}
'언리얼게임프로젝트 > 슈팅게임 C++' 카테고리의 다른 글
UI제작하기 언리얼슈팅게임 C++ (0) | 2025.03.25 |
---|---|
충돌이벤트와 델리게이트 Delegate (0) | 2025.03.12 |
Ureal C++ Collision처리 (0) | 2025.03.12 |
EnemyActor Factory 생성하기 Spawn (0) | 2025.03.12 |
Unreal Shooting Game C++ EnemyActor (0) | 2025.03.11 |