[Unreal][C++] 바라보는 Actor에게 효과 주기

2024. 5. 12. 13:51·📝 Game/✏ Unreal

카메라가 아이템을 바라보면 그 아이템에게 반짝이는 효과를 줄 것이다.

 

아이템 효과

 

1. Overlay Material

Overlay Material은 기존 액터에 설정된 Material에 추가로 블렌드 하기 위한 Material이다. 외곽선, 빛 등 여러 여러 효과를 넣을 수 있다.

 

Overlay Material

 

캐릭터가 이 액터를 바라볼 때 해당 머터리얼에 M_Outline 머터리얼을 Set 하는 방식으로 구현할 것이다.

 

Set Overlay Material

 

M_Outline 머터리얼은 위에서 아래로 빛을 내며 Highlight 되는 머터리얼이다.

 

M_Outline Viewport

 

구현은 다음과 같다.

 

M_Outline

  • Blend Mode: Additive
  • Shading Model: Unlit

 

2. Sphere Trace By Channel

캐릭터가 액터를 바라보는지 확인하기 위해 Trace를 활용할 것이다.

 

Trace

 

먼저 특정 액터만 탐지하기 위해 Trace 채널을 하나 생성한 후, 그 특정 액터에서 생성한 Trace Responses를 Block으로 변경한다.

 

Project Setting > Collision

 

1) 블루프린트 구현

캐릭터 블루프린트의 Event Tick 노드에서 Trace 탐지를 위한 구현이 필요하다.

 

Sphere Trace By Channel

  • Start: SpringArmCamera의 월드 위치
  • End: SpringArmCamera의 월드 위치 +  SpringArmCamera와 FollowCamera 사이의 방향 벡터 * 탐지할 범위

Set Outline

 

탐지되었을 땐 Outline을 활성화시키고, 탐지되지 않았을 때 Outline을 비활성화시키도록 하면 된다.

 

2) C++ 구현

Start = CameraBoom->GetComponentLocation();
End = UKismetMathLibrary::GetDirectionUnitVector(Start, FollowCamera->GetComponentLocation()) * -500 + Start;
IsHit = UKismetSystemLibrary::SphereTraceSingle(
	GetWorld(), Start, End, 100,
	ETraceTypeQuery::TraceTypeQuery3, true,
	ToIgnore,
	EDrawDebugTrace::None, OutHit, true);

if (IsHit)
{
	FocusItem = Cast<AItemBase>(OutHit.GetActor());

	if (IsValid(FocusItem))
	{
		FocusItem->SetOutline(true);
	}
}
else 
{
	if (IsValid(FocusItem))
	{
		FocusItem->SetOutline(false);
		FocusItem = NULL;
	}
}

 

출처

https://www.youtube.com/watch?v=BO_1T6xgZRE

저작자표시 (새창열림)
'📝 Game/✏ Unreal' 카테고리의 다른 글
  • [Unreal] Object, Actor, Component
  • [Unreal] UMG
  • [Unreal][C++] 캐릭터 카메라 개선
  • [Unreal][C++] 액터 생성
Blxxming
Blxxming
CS 지식과 공부하다 배운 것, 경험한 것 등을 기록하는 블로그입니다.
  • Blxxming
    💡번뜩💡
    Blxxming
  • 전체
    오늘
    어제
  • 공지사항

    • Tech Interview
    • 📚 Tech (246)
      • 📝 Computer Science (96)
        • ✏ OS (12)
        • ✏ Network & Web (10)
        • ✏ Database (11)
        • ✏ Data Structure (6)
        • ✏ Algorithm (40)
        • ✏ Design Pattern (9)
        • ✏ Cloud Computing (3)
        • ✏ (5)
      • 📝 Language (73)
        • ✏ Language (6)
        • ✏ C & C++ (11)
        • ✏ C# (19)
        • ✏ JAVA (37)
      • 📝 Game (43)
        • ✏ Computer Graphics (2)
        • ✏ Unity (14)
        • ✏ Unreal (26)
        • ✏ (1)
      • 📝 Book (34)
        • ✏ Effective (3)
        • ✏ Game Server (16)
        • ✏ Clean Code (14)
        • ✏ (1)
  • hELLO· Designed By정상우.v4.10.0
Blxxming
[Unreal][C++] 바라보는 Actor에게 효과 주기
상단으로

티스토리툴바