ExoWest/Source/Exo/Private/Player/InteractionComponent.cpp
Kubson96 e70f96df2c fix: fixed linetrace after locking character pitch
Fixed linetrace, because it was follow only horizontal axis after locking character pitch.
Added empty GunBase class with BP revolver item.
2025-03-15 13:48:39 +01:00

56 lines
1.4 KiB
C++

#include "Player/InteractionComponent.h"
UInteractionComponent::UInteractionComponent()
{
PrimaryComponentTick.bCanEverTick = true;
}
void UInteractionComponent::BeginPlay()
{
Super::BeginPlay();
}
void UInteractionComponent::CheckForInteractable()
{
AActor* Owner = GetOwner();
APawn* PawnOwner = Cast<APawn>(Owner);
if (!PawnOwner || !PawnOwner->GetController()) return;
FVector ViewLocation;
FRotator ViewRotation;
PawnOwner->GetController()->GetPlayerViewPoint(ViewLocation, ViewRotation);
FVector ForwardVector = ViewRotation.Vector();
FVector LineStart = Owner->GetActorLocation();
FVector LineEnd = LineStart + (ForwardVector * InteractionDistance);
FHitResult HitResult;
FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(Owner);
bool bHit = GetWorld()->LineTraceSingleByChannel(HitResult, LineStart, LineEnd, ECC_Visibility, QueryParams);
if (bHit && HitResult.GetActor() && HitResult.GetActor()->Implements<UInteractable>())
{
InteractedActor = HitResult.GetActor();
}
else
{
InteractedActor = nullptr;
}
if (bShowDebugLine)
DrawDebugLine(GetWorld(), LineStart, LineEnd, FColor::Red, false, 1.0f, 0, 1.0f);
}
void UInteractionComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
{
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
CheckForInteractable();
}