Grenade Launcher Challenge: C++/Blueprints
Grenade Launcher Challenge: C++/Blueprints es el quinto 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 hay que especializar la clase SWeapon en SLauncher y sobrescribir la función Fire(). La nueva funcionalidad será disparar proyectiles que reboten, exploten a los 3 segundos (con un Timer) y hagan daño en area. He aprovechado para añadir un nuevo Socket en el esqueleto del Player para guardar el segundo arma y he implementado en BP la función para intercambiar entre una y otra.
.h
// Creative Commons - Reconocimiento (by)
#pragma once
#include "CoreMinimal.h"
#include "SWeapon.h"
#include "SLauncher.generated.h"
class ASProjectile;
/**
*
*/
UCLASS()
class COOPGAME_API ASLauncher : public ASWeapon
{
GENERATED_BODY()
protected:
virtual void Fire() override;
public:
/** Projectile class to spawn */
UPROPERTY(EditDefaultsOnly, Category = "Projectile")
TSubclassOf<ASProjectile> ProjectileClass;
};
.cpp
// Creative Commons - Reconocimiento (by)
#include "../Public/SLauncher.h"
#include "DrawDebugHelpers.h"
#include "Kismet/GameplayStatics.h"
#include "Particles/ParticleSystem.h"
#include "Components/SkeletalMeshComponent.h"
#include "Particles/ParticleSystemComponent.h"
#include "Public/SProjectile.h"
void ASLauncher::Fire()
{
AActor* MyOwner = GetOwner();
if (ProjectileClass && MyOwner)
{
FVector EyeLocation;
FRotator EyeRotation;
MyOwner->GetActorEyesViewPoint(EyeLocation, EyeRotation);
// try and fire a projectile
FVector MuzzleLocation = MeshComp->GetSocketLocation("MuzzleSocket");
FRotator MuzzleRotation = EyeRotation;
//Set Spawn Collision Handling Override
FActorSpawnParameters ActorSpawnParams;
ActorSpawnParams.SpawnCollisionHandlingOverride = ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
// spawn the projectile at the muzzle
GetWorld()->SpawnActor<ASProjectile>(ProjectileClass, MuzzleLocation, MuzzleRotation, ActorSpawnParams);
if (MuzzleEffect)
{
UGameplayStatics::SpawnEmitterAttached(MuzzleEffect, MeshComp, MuzzleSocketName);
}
}
}
Destacado .h
UFUNCTION() void ExecuteBoom(); UPROPERTY(EditDefaultsOnly, BlueprintREadOnly, Category = "Weapon") UParticleSystem* BoomEffect;
Destacado .cpp
// Called when the game starts or when spawned
void ASProjectile::BeginPlay()
{
Super::BeginPlay();
GetWorldTimerManager().ClearTimer(TimeHandle_Boom);
GetWorldTimerManager().SetTimer(TimeHandle_Boom, this, &ASProjectile::ExecuteBoom, 3.0f);
}
void ASProjectile::ExecuteBoom()
{
UGameplayStatics::SpawnEmitterAtLocation(GetWorld(), BoomEffect, GetActorLocation());
TArray<AActor*> Actors;
UGameplayStatics::ApplyRadialDamage(this, 60.0f, GetActorLocation(),200.0f, DamageType,Actors ,this,GetInstigatorController(),true);
DrawDebugSphere(GetWorld(), GetActorLocation(), 200.0f, 12, FColor::Red, false, 1);
Destroy();
}
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: Grenade Launcher Challenge: C++/Blueprints [project]
Demo: Grenade Launcher 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.
