the take damage function is called but it doesn’t lower the health
void ACharacter::Attack()
{
FHitResult* HitResult = new FHitResult();
FVector StartTrace = Hero2CameraComponent->GetComponentLocation();
FVector ForwardVector = Hero2CameraComponent->GetForwardVector();
FVector EndTrace = (ForwardVector* 500) + StartTrace;
FCollisionQueryParams* CQP = new FCollisionQueryParams();
if (GetWorld()->LineTraceSingleByChannel(*HitResult, StartTrace, EndTrace, ECC_Visibility, *CQP))
{
DrawDebugLine(GetWorld(), StartTrace, EndTrace, FColor(255, 0, 0), true);
HitResult->GetActor()->TakeDamage(20.f, FDamageEvent(), GetController(), this);
}
else
{
// do nothing
}
}
float ACharacter::TakeDamage(float Damage, FDamageEvent const & DamageEvent, AController * EventInstigator, AActor * DamageCauser)
{
if (Role < ROLE_Authority || Health <= 0.0f)
return 0.0f;
const float ActualDamage = Super::TakeDamage(Damage, DamageEvent, EventInstigator, DamageCauser);
if (ActualDamage > 0.0f)
{
Health -= ActualDamage;
if (Health <= 0.0f)
{
// actor dies
}
}
return ActualDamage;
}