My additions to BattleTank

I am going to use this topic to showcase what I’ve added/changed to my BattleTank game. Feedback is always welcome and if anybody else would like to share their additions that is also welcome.

so the first thing that I really wanted to add was some way to show visually when a tank was destroyed. For me the best/first way I thought to do this was to add another particle system which would make the tank appear to be on fire.

My first thought was to try to use the SpawnActor function which was used in the TankAimingComponent.cpp but after lots of trial and error I came to the conclusion that this was not the way to do it. After much research I came to find UGameplayStatics::SpawnEmitterAttached and finally got it to work.

My process went as follows:

  1. Created a socket on the TankBody and named it “Fire” where I wanted the particle system to spawn.

  2. Added the following lines in the private section of Tank.h

    UPROPERTY(EditDefaultsOnly, Category = “Setup”)
    UParticleSystem* DeadTankParticleSystem = nullptr;


  1. Added the following lines of code in Tank.cpp in the TakeDamage function directly after the broadcast

    if (CurrentHealth <= 0)
    {
    OnDeath.Broadcast();
    auto RootMeshComponent = Cast(GetRootComponent());
    if (!RootMeshComponent) { return DamageToApply; }

     UGameplayStatics::SpawnEmitterAttached(
     	DeadTankParticleSystem,
     	RootMeshComponent,
     	FName("Fire"),
     	RootMeshComponent->GetSocketLocation(FName("Fire")),
     	RootMeshComponent->GetSocketRotation(FName("Fire")),
     	EAttachLocation::KeepWorldPosition,
     	true
     );
    

    }

  2. Once compiled I went into the Tank_BP and assigned the appropriate particle system

  3. Rejoice

Last thing to mention is that during the video where Ben asked us to make the Turret destroyable I actually just made it of type Tank instead of Pawn, which allowed me to treat it as an enemy in the same way as the tanks. This also allowed me to add the same particle system on destroy

1 Like

Privacy & Terms