// Fill out your copyright notice in the Description page of Project Settings. #include "Enemys/Enemy.h" #include "Player/AstralQuestCharacter.h" // Sets default values AEnemy::AEnemy() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; } // Called when the game starts or when spawned void AEnemy::Attack() { if (Player->GetController() == nullptr) { return; } FVector EyesLoc; FRotator EyesRot; Player->GetController()->GetPlayerViewPoint(EyesLoc, EyesRot); FVector TraceStart = EyesLoc; FVector TraceEnd = (EyesRot.Vector() * Range) + TraceStart; FHitResult TraceHit; FCollisionQueryParams QueryParams; QueryParams.AddIgnoredActor(this); if (GetWorld()->LineTraceSingleByChannel(TraceHit, TraceStart, TraceEnd, ECC_Visibility, QueryParams)) { if (TraceHit.GetActor()) { TempPlayer = Cast(TraceHit.GetActor()); if (TempPlayer) { if (TempPlayer->Defense > 0) { TempPlayer->Health -= (AttackDamage / TempPlayer->Defense); } else { TempPlayer->Health -= AttackDamage; } } } } } // Called when the game starts or when spawned void AEnemy::BeginPlay() { Super::BeginPlay(); } // Called every frame void AEnemy::Tick(float DeltaTime) { Super::Tick(DeltaTime); if (Health < 1) { GetWorld()->DestroyActor(this); } }