i have a line trace set up in my Player.CPP
// Get player view point
FVector PlayerViewPointLocation;
FRotator PlayerViewPointRotation;
GetWorld()->GetFirstPlayerController()->GetPlayerViewPoint(OUT PlayerViewPointLocation, OUT PlayerViewPointRotation);
// Log out to test
//UE_LOG(LogTemp, Warning, TEXT("Location: %s, Position: %s"), *PlayerViewPointLocation.ToString(), *PlayerViewPointRotation.ToString());
FVector LineTraceEnd = PlayerViewPointLocation + PlayerViewPointRotation.Vector() * Reach;
// Draw a red trace in the world to visualise
//DrawDebugLine(GetWorld(), PlayerViewPointLocation, LineTraceEnd, FColor(255, 0, 0), false, 0.f, 0.f, 20.f);
// set up query parameters
FCollisionQueryParams TraceParameters(FName(TEXT("")), false, GetWorld()->GetFirstPlayerController()->GetPawn());
// Line trace
FHitResult Hit;
GetWorld()->LineTraceSingleByObjectType(OUT Hit, PlayerViewPointLocation, LineTraceEnd, FCollisionObjectQueryParams(ECollisionChannel::ECC_GameTraceChannel1), TraceParameters);
And i have a OpenDoor.CPP which i have simple code to open a door
InputComponent = GetWorld()->GetFirstPlayerController()->GetPawn()->FindComponentByClass();
if (InputComponent)
{
InputComponent->BindAction("Interact", IE_Pressed, this, &UDoor::OpenDoor);
}
void UDoor::OpenDoor()
{
JustInteractedWithDoor = false;
if (DoorHit && !DoorIsOpen && !JustInteractedWithDoor)
{
OpenDoorBP.Broadcast();
DoorIsOpen = true;
JustInteractedWithDoor = true;
}
if (DoorHit && DoorIsOpen && !JustInteractedWithDoor)
{
CloseDoorBP.Broadcast();
DoorIsOpen = false;
JustInteractedWithDoor = true;
}
}
I want the code in the Door.CPP to Run when the Line trace from Player.CPP hits the object that it is looking for, how would i do that?