How would i use line trace in c++

Here’s the whole code you need to do a line trace in the c++

Enjoy!

FCollisionQueryParams RV_TraceParams = FCollisionQueryParams(FName(TEXT("RV_Trace")), true, this);
RV_TraceParams.bTraceComplex = true;
RV_TraceParams.bTraceAsyncScene = true;
RV_TraceParams.bReturnPhysicalMaterial = false;

//Re-initialize hit info
FHitResult RV_Hit(ForceInit);
	
//call GetWorld() from within an actor extending class
GetWorld()->LineTraceSingle(
	RV_Hit,		//result
	Start,	//start
	End, //end
	ECC_Pawn, //collision channel
	RV_TraceParams
);

once you do the trace,

RV_Hit.bBlockingHit //did hit something? (bool)
RV_Hit.GetActor(); //the hit actor if there is one
RV_Hit.ImpactPoint;  //FVector
RV_Hit.ImpactNormal;  //FVector
3 Likes