Thanks for the recommendations! One last thing that I was wondering was is it bad practice to cast to different classes in one function for example having a raycast function shoot a raycast and casting to lets say two classes and having an if statement to see which class was hit and based on the class hit will execute different events.
Like this:
Player.CPP
void APlayer::Shoot()
{
//InstantShot is the raycast function and is being used in the input function Shoot
FHitResult Hit = InstantShot();
ADamageableActorBase* ActorHit = Cast<ADamageableActorBase>(Hit.Actor);
if (ActorHit && ActorHit->isDamageable)
{
ActorHit->TakeAttack();
DrawDebugBox(GetWorld(), Hit.ImpactPoint, FVector(10.0f, 10.0f, 10.0f), FColor::Green, false, 5.0f);
}
APlayer* Target = Cast<APlayer>(Hit.Actor);
if (Target && Target->IsAttackable)
{
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Green, FString::Printf(TEXT("Character hit: %s"), *Hit.GetActor()->GetName()));
DrawDebugBox(GetWorld(), Hit.ImpactPoint, FVector(10.0f, 10.0f, 10.0f), FColor::Green, false, 5.0f);
switch (UGameplayStatics::GetSurfaceType(Hit))
{
case SurfaceType1:
UGameplayStatics::ApplyPointDamage(Target, 50.0f, Hit.TraceStart, Hit, GetInstigatorController(), this, UDamageType::StaticClass());
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Green, FString::SanitizeFloat(Target->Health->HP));
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Green, FString::Printf(TEXT("SurfaceType: HeadShot")));
break;
case SurfaceType2:
UGameplayStatics::ApplyPointDamage(Target, 25.0f, Hit.TraceStart, Hit, GetInstigatorController(), this, UDamageType::StaticClass());
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Green, FString::SanitizeFloat(Target->Health->HP));
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Green, FString::Printf(TEXT("SurfaceType: FleshShot")));
break;
default:
UGameplayStatics::ApplyPointDamage(Target, 5.0f, Hit.TraceStart, Hit, GetInstigatorController(), this, UDamageType::StaticClass());
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Green, FString::SanitizeFloat(Target->Health->HP));
GEngine->AddOnScreenDebugMessage(-1, 1.0f, FColor::Green, FString::Printf(TEXT("Failed!")));
}
}
}