Hi, I’m using Unreal 5.1, following the Toon Tanks course.
At the end of the “Handling Pawn Death” video, everything works as expected except the Tank, which absolutely refuses to die. It gets hit (it logs out messages when hit and damaged) but it never dies.
The turrets work fine. They do disappear as they should/when they die.
Here goes the code:
(Thanks in advance!)
// Fill out your copyright notice in the Description page of Project Settings.
#include "Tank.h"
#include "Camera/CameraComponent.h"
#include "GameFramework/SpringArmComponent.h"
#include "Kismet/GameplayStatics.h"
ATank::ATank()
{
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("Spring Arm"));
SpringArm->SetupAttachment(RootComponent);
Camera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera"));
Camera->SetupAttachment(SpringArm);
}
void ATank::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent)
{
Super::SetupPlayerInputComponent(PlayerInputComponent);
PlayerInputComponent->BindAxis(TEXT("MoveForward"), this, &ATank::Move);
PlayerInputComponent->BindAxis(TEXT("Turn"), this, &ATank::Turn);
PlayerInputComponent->BindAction(TEXT("Fire"), IE_Pressed, this, &ATank::Fire);
}
void ATank::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
if (TankPlayerController)
{
FHitResult HitResult;
TankPlayerController->GetHitResultUnderCursor(
ECollisionChannel::ECC_Visibility,
false,
HitResult
);
RotateTurret(HitResult.ImpactPoint);
}
}
void ATank::HandleDestruction()
{
Super::HandleDestruction();
SetActorHiddenInGame(true);
SetActorTickEnabled(false);
}
void ATank::BeginPlay()
{
Super::BeginPlay();
TankPlayerController = Cast<APlayerController>(GetController());
}
void ATank::Move(float Value)
{
FVector DeltaLocation = FVector::ZeroVector;
// X = Value * DeltaTime * Speed
DeltaLocation.X = Value * Speed * UGameplayStatics::GetWorldDeltaSeconds(this);
AddActorLocalOffset(DeltaLocation, true);
}
void ATank::Turn(float Value)
{
FRotator DeltaRotation = FRotator::ZeroRotator;
DeltaRotation.Yaw = Value * TurnRate * UGameplayStatics::GetWorldDeltaSeconds(this);
AddActorLocalRotation(DeltaRotation, true);
}