I’m using this on my player/character that will be used as part of my lock on functions.
FHitResult testHitResult(ForceInit);
UWorld* TheWorld = this->GetWorld();
FVector testStartFVector = this->GetActorLocation();
FVector testEndFVector = testStartFVector + GetActorForwardVector() * 1000.0f;
FColor debugColor = FColor::Red;
FCollisionQueryParams TraceParams(TEXT("MyTrace"), true, this);
TraceParams.bTraceComplex = true;
TraceParams.bTraceAsyncScene = true;
TraceParams.bReturnPhysicalMaterial = false;
if (TheWorld->LineTraceSingle(testHitResult, testStartFVector, testEndFVector, ECC_WorldStatic, TraceParams))
{
ALivingEntity* tempActor = (testHitResult.GetActor() != NULL ? Cast<ALivingEntity>(testHitResult.GetActor()) : NULL);
if (tempActor != NULL)
{
//GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::Blue, TEXT("Found"));
debugColor = FColor::Red;
Target = tempActor;
//DrawDebugBox(TheWorld, testHitResult.Location, FVector(10, 10, 10), debugColor);
}
}
This all works but as it uses my characters direction to do the trace I hadn’t noticed that it ignores terrain as I can actually see the target my self.
I’ve put this code onto my bots, and my bots know the location of their target, so the trace always puts a line straight to them. From their eyes to their targets location.
for some reason they seem to ignore the terrain for collision, any Ideas?
My terrain is set to BlockAll.