Hi
How would I go about adding this BP code into C++, more so the Interface message
What I’m looking for is to be able to call Possess()
on another instance on the same class while passing in the Controller of the one who instigated the line trace
What I’ve got so far in my .cpp file
void ARayCastTestCharacter::PossessCharacter()
{
AController* PossingController = this->GetController();
FVector Start = FirstPersonCameraComponent->GetComponentLocation();
FVector End = Start + FirstPersonCameraComponent->GetForwardVector() * PossessDist;
FHitResult HitResult;
FCollisionQueryParams Param;
TArray <AActor*>ActorsToIgnore;
bool HasHit = UKismetSystemLibrary::LineTraceSingle(GetWorld(),
Start,
End,
ETraceTypeQuery::TraceTypeQuery3,
false,
ActorsToIgnore,
EDrawDebugTrace::ForDuration,
HitResult,
true);
DrawDebugLine(GetWorld(), Start, End, FColor::Green, false, 5);
DrawDebugSphere(GetWorld(), HitResult.ImpactPoint, 10, 10, FColor::Red, false, 5);
if (HasHit)
{
PossessAI(PossingController);
UE_LOG(LogTemp, Warning, TEXT("New Actor hit by trace %s"), *HitResult.GetActor()->GetActorNameOrLabel());
}
}
void ARayCastTestCharacter::PossessAI(AController* PossessingController)
{
if (PossessingController) { UE_LOG(LogTemp, Error, TEXT("(PossessingController) was nullptr")); return; }
PossessingController->Possess(this);
}