Notice
Recent Posts
Recent Comments
Link
스토리지
충돌 판정 본문
기본적으로 Actor들은 다 Collision을 지원하는 거 같다. Detail 패널에서 Collision을 검색하면 확인 할 수 있다.
1. Collision Presets
대충 몇개만 보자면
- NoCollision : 충돌 판정 X
- BlockAll : 충돌 판정 있어서 막히는 것
- OverlapAll : 충돌 판정 있지만 겹쳐지는 것
2. Collision Response
각각의 객체에 대해 충돌판정 유뮤를 정할 수 있다.
위의 사진은 해당 객체가 Camera와 충돌하지 않고 Pawn과는 Overlap이 가능한 것을 체크해놓았다. 그 이외에는 전부 Block이다.
3. 코드에서 충돌 델리게이트 구성
USceneComponent에서 상속받는 UPrimitiveComponent.h라는 곳에 해당 함수에 대한 델리게이트 설명이 있다.
/** Delegate for notification of start of overlap with a specific component */
DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_SixParams( FComponentBeginOverlapSignature, UPrimitiveComponent, OnComponentBeginOverlap, UPrimitiveComponent*, OverlappedComponent, AActor*, OtherActor, UPrimitiveComponent*, OtherComp, int32, OtherBodyIndex, bool, bFromSweep, const FHitResult &, SweepResult);
/** Delegate for notification of end of overlap with a specific component */
DECLARE_DYNAMIC_MULTICAST_SPARSE_DELEGATE_FourParams( FComponentEndOverlapSignature, UPrimitiveComponent, OnComponentEndOverlap, UPrimitiveComponent*, OverlappedComponent, AActor*, OtherActor, UPrimitiveComponent*, OtherComp, int32, OtherBodyIndex);
내 코드에서 사용할 땐 다음과 같이 사용한다.
- 충돌 감지할 컴포넌트 설정 (여기서는 USphereComponent)
- 델리게이트에 넣을 함수 생성
- BeginPlay 함수에서 델리게이트 할당
Item.h
UPROPERTY(VisibleAnywhere)
USphereComponent *Sphere;
Item.cpp
void AItem::BeginPlay()
{
Super::BeginPlay();
// 델리게이트에 함수 할당
Sphere->OnComponentBeginOverlap.AddDynamic(this, &AItem::OnSphereOverlap);
Sphere->OnComponentEndOverlap.AddDynamic(this, &AItem::OnSphereOvelapEnd);
}
void AItem::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
const FString OtherActorName = OtherActor->GetName();
FLogging::LogScreen(OtherActorName, FColor::Red);
}
void AItem::OnSphereOvelapEnd(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
{
FString Message = FString::Printf(TEXT("OnSphereOverlapEnd: %s"), *OtherActor->GetName());
FLogging::Log(Message, ELogVerbosity::Warning);
}
- FComponentBeginOverlapSignature와 FComponentEndOverlapSignature은 포인터가 아니기 때문에 멤버에 '.'로 접근한다.
- AddDynamic 함수를 통해 델리게이트를 할당해준다. 함수 주소를 넣어준다.
'Unreal Engine > 0. Unreal 5' 카테고리의 다른 글
아이템 주워서 팔에 붙이기 (0) | 2023.07.21 |
---|---|
IK Rig (0) | 2023.07.18 |
애니메이션 적용 (0) | 2023.07.14 |
언리얼 Inverse Kinematic (0) | 2023.07.14 |
Character (0) | 2023.07.13 |
Comments