Basic AI + Networking Challenge: C++/Blueprints
Basic AI + Networking Challenge: C++/Blueprints es el octavo reto propuesto por el curso Unreal Engine 4 Mastery: Create Multiplayer Games with C++ de Tom Looman certificado por Epic Games disponible en la plataforma Udemy.
A lo largo del curso se desarrollarán dos juegos con base en C++ y extendiendo la funcionalidad con Blueprints. Los dos juegos son multijugador y se profundizará también en AI y para reforzar los diferentes temas se proponen distintos retos.
En esta ocasión se ha implementado un pequeño robot que busca al jugador con funciones de pathfinder de UE4 y se mueve aplicandole fuerza. Las principales características del bot son:
- Cuando está cerca del jugador explota.
- La explosión se ve amplificada si hay cerca más bots.
- Se produce un cambio a nivel visual ya que al haber más bots cerca además de aplicar más daño se iluminan en rojo.
- Se pueden destruir disparándoles.
- Se aplica un impulso radial a los elementos físicos cercanos.
- El sonido de rodamiento se amplifica utilizando la velocidad del objeto dándo la sensación de que para y empieza a sonar al moverse.
Destacado .h
// Next point in navigation path FVector NextPathPoint; void SelfDesctruct(); void DamageSelf(); // Find nearby enemies and grow in 'power level' based on the amount void onCheckNearbyBots(); // The power boost of the bot, affects damged caused to enemies and color of the bot (range: 1 to 4) int32 PowerLevel;
Destacado .cpp
// Called when the game starts or when spawned
void ASTrackerBot::BeginPlay()
{
Super::BeginPlay();
MatInst = MeshComp->CreateAndSetMaterialInstanceDynamicFromMaterial(0, MeshComp->GetMaterial(0));
FTimerHandle TimerHandle_CheckPowerLevel;
GetWorldTimerManager().SetTimer(TimerHandle_CheckPowerLevel, this, &ASTrackerBot::onCheckNearbyBots, 1.0f, true);
if (Role == ROLE_Authority)
{
// Find initial move to
NextPathPoint = GetNextPathPoint();
}
}
void ASTrackerBot::onCheckNearbyBots()
{
TArray<AActor*> OverlapingBots;
SphereNearBotComp->GetOverlappingActors(OverlapingBots);
//if (DebugTrackerBotDrawing > 0) UE_LOG(LogTemp, Log, TEXT("Nearby bots: BotName= %s - NearbyBots=%s"), *GetName(), *FString::SanitizeFloat(OverlapingBots.Num()));
int32 NrOfBots = OverlapingBots.Num();
const int32 MaxPowerLevel = 4;
PowerLevel = FMath::Clamp(NrOfBots, 0, MaxPowerLevel);
float Alpha = PowerLevel / (float)MaxPowerLevel;
if (MatInst) {
MatInst->SetScalarParameterValue("PowerLevelAlpha", Alpha);
}
}
void ASTrackerBot::SelfDesctruct()
{
if (bExploded)
{
return;
}
bExploded = true;
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), ExplosionEffect, GetActorLocation());
UGameplayStatics::PlaySoundAtLocation(this, ExplodeSound, GetActorLocation());
MeshComp->SetVisibility(false,true);
MeshComp->SetCollisionEnabled(ECollisionEnabled::NoCollision);
if (Role == ROLE_Authority)
{
// Apply Damage!
if (DebugTrackerBotDrawing > 0) UE_LOG(LogTemp, Log, TEXT("Execute destruction,Base %s - PowerLevelUp : %s"), *FString::SanitizeFloat(ExplosionDamage), *FString::SanitizeFloat(PowerLevel));
TArray<AActor*> IgnoredActors;
IgnoredActors.Add(this);
float FinalDamage = ExplosionDamage + (ExplosionDamage * PowerLevel);
UGameplayStatics::ApplyRadialDamage(this, FinalDamage, GetActorLocation(), ExplosionRadius, nullptr, IgnoredActors, this, GetInstigatorController(), true);
RadialForceComp->FireImpulse();
// Delete Actor inmediately
SetLifeSpan(2.0f);
if (DebugTrackerBotDrawing > 0)DrawDebugSphere(GetWorld(), GetActorLocation(), ExplosionRadius, 12, FColor::Red, false, 2.0f, 0, 1.0f);
}
}
A continuación os dejaré los enlaces al código, demo y al video en youtube para que podáis ver más. De momento me está gustando el curso pero al final compartiré una valoración general por si a alguien le pueda interesar que sepa más o menos que esperar del mismo.
Repositorio: Basic AI + Networking Challenge: C++/Blueprints [project]
Demo: Basic AI + Networking Challenge: C++/Blueprints [demo]
Curso: Unreal Engine 4 Mastery: Create Multiplayer Games with C++

Lvl 35 | #Porting #GameDev en Catness Game Studios | Ex #AI #GameDev en The Crown of Wu de Red Mountain | Padre de Baby T-Rex.
