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
right i tried doing
if(RV_Hit.GetActor()->GetActorClass() == AMyProjectCharacter()){
}
but that won’t work because i need the params how do i do an if statement to do something if i hit a certain actor.
FHitResult Hit = GetWorld()->LineTraceSingle(parameters here). LineTraceSingle will return a hit result called Hit which you will have to define and with hit you can manipulate it like Hit.Location. For more reference look inside the header file in the Rocket directory called World.h. This should help you and now for your information there are different kinds of traces like trace rectangle or sphere with an area that you can trace, like in Unity. I hope this helps!
This is an archived post and there have been many changes to the engine since this was last seen. If you are seeing a similar issue in a more current engine, please create a new post to track the issue you’re having.