본문 바로가기

강동새싹언리얼수업/언리얼

211124 LineTrace C++

실습에서는 Input Action을 만들어 E를 누르면 InterActionPositive가 실행되게 바인딩했다. C++에서는 라인을 그려주지 않기 때문에 DrawDebugHelpers.h를 추가해주고 DrawDebugLine(), DrawDebugCirdle()등을 실현해주어야 한다.

#include "DrawDebugHelpers.h"


//......



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


	FCollisionQueryParams _TraceParams;
	if (GetWorld()->LineTraceSingleByChannel(_HitOut, _Start, _End, ECC_Visibility, _TraceParams)) {
		_Start = GetActorLocation();
		_End = _HitOut.ImpactPoint;
	}
	else
	{
		_Start = GetActorLocation();
		_End = (GetActorRotation().Vector() * 20000);
	}
	DrawDebugLine(
		GetWorld(),
		_Start,
		_End,
		FColor::Magenta,
		true,
		10, 0, 5);

	DrawDebugSphere(
		GetWorld(),
		_End,
		10.f,
		5,
		FColor::Magenta,
		true,
		10, 0, 5);
	GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Magenta, TEXT("E Key Pressed "));

	

}

https://blog.naver.com/nhemch123/223183631419

 

이득우의 언리얼 C++ 게임 개발의 정석 08.14

교재를 공부하면서 새로 배운 자료 구조, 함수 및 C++ 정보들을 정리하는 글입니다. ● 게임 세계에 속해...

blog.naver.com

 

'강동새싹언리얼수업 > 언리얼' 카테고리의 다른 글

231127 DrawDebugSphere() and HitResult  (0) 2023.11.28
231127 라인트레이스  (0) 2023.11.27
231125 205 특강  (2) 2023.11.25
231123 Widget in Actor C++  (0) 2023.11.24
231123 LineTrace  (0) 2023.11.23