61 lines
1.6 KiB
C++
61 lines
1.6 KiB
C++
|
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||
|
|
|
||
|
|
|
||
|
|
#include "Characters/Components/ShootingComponent.h"
|
||
|
|
|
||
|
|
// Sets default values for this component's properties
|
||
|
|
UShootingComponent::UShootingComponent()
|
||
|
|
{
|
||
|
|
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
|
||
|
|
// off to improve performance if you don't need them.
|
||
|
|
PrimaryComponentTick.bCanEverTick = true;
|
||
|
|
|
||
|
|
// ...
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
// Called when the game starts
|
||
|
|
void UShootingComponent::BeginPlay()
|
||
|
|
{
|
||
|
|
Super::BeginPlay();
|
||
|
|
|
||
|
|
// ...
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
void UShootingComponent::Shoot()
|
||
|
|
{
|
||
|
|
AActor* Owner = GetOwner();
|
||
|
|
|
||
|
|
FVector LineStart = Owner->GetActorLocation();
|
||
|
|
FVector ForwardVector = Owner->GetActorForwardVector();
|
||
|
|
FVector LineEnd = LineStart + (ForwardVector * MaxRange);
|
||
|
|
|
||
|
|
FHitResult HitResult;
|
||
|
|
FCollisionQueryParams QueryParams;
|
||
|
|
QueryParams.AddIgnoredActor(Owner);
|
||
|
|
|
||
|
|
bool bHit = GetWorld()->LineTraceSingleByChannel(HitResult, LineStart, LineEnd, ECC_Visibility, QueryParams);
|
||
|
|
|
||
|
|
if (bHit && HitResult.GetActor() && HitResult.GetActor()->Implements<UDamageable>())
|
||
|
|
{
|
||
|
|
IDamageable::Execute_TakeDamage(HitResult.GetActor(), DamageValue);
|
||
|
|
|
||
|
|
UE_LOG(LogTemp, Warning, TEXT("Shoot"));
|
||
|
|
}
|
||
|
|
|
||
|
|
if (bShowDebugLine)
|
||
|
|
DrawDebugLine(GetWorld(), LineStart, LineEnd, FColor::Red, false, 1.0f, 0, 1.0f);
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
// Called every frame
|
||
|
|
void UShootingComponent::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction)
|
||
|
|
{
|
||
|
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||
|
|
|
||
|
|
// ...
|
||
|
|
}
|
||
|
|
|