Section 13: The Enemy Class - Lecture 271

Grux Physics Asset
This commit is contained in:
charnet3d 2024-03-03 20:25:39 +01:00
parent e70a5a290b
commit 5352846678
8 changed files with 27 additions and 11 deletions

View File

@ -114,6 +114,5 @@ DoubleClickTime=0.200000
DefaultPlayerInputClass=/Script/EnhancedInput.EnhancedPlayerInput DefaultPlayerInputClass=/Script/EnhancedInput.EnhancedPlayerInput
DefaultInputComponentClass=/Script/EnhancedInput.EnhancedInputComponent DefaultInputComponentClass=/Script/EnhancedInput.EnhancedInputComponent
DefaultTouchInterface=/Engine/MobileResources/HUD/DefaultVirtualJoysticks.DefaultVirtualJoysticks DefaultTouchInterface=/Engine/MobileResources/HUD/DefaultVirtualJoysticks.DefaultVirtualJoysticks
-ConsoleKeys=Tilde
+ConsoleKeys=Tilde +ConsoleKeys=Tilde

Binary file not shown.

BIN
Content/_Game/Enemies/EnemyBP.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/_Game/HUD/HitNumber.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/_Game/Maps/DefaultMap.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -20,7 +20,6 @@ AEnemy::AEnemy() :
{ {
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it. // Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.bCanEverTick = true;
} }
// Called when the game starts or when spawned // Called when the game starts or when spawned
@ -78,11 +77,26 @@ void AEnemy::DestroyHitNumber(UUserWidget* HitNumber)
HitNumber->RemoveFromParent(); HitNumber->RemoveFromParent();
} }
void AEnemy::UpdateHitNumbers()
{
for (auto& HitPair : HitNumbers)
{
UUserWidget* HitNumber{ HitPair.Key };
const FVector Location{ HitPair.Value };
FVector2D ScreenPosition;
UGameplayStatics::ProjectWorldToScreen(GetWorld()->GetFirstPlayerController(),
Location, ScreenPosition);
HitNumber->SetPositionInViewport(ScreenPosition);
}
}
// Called every frame // Called every frame
void AEnemy::Tick(float DeltaTime) void AEnemy::Tick(float DeltaTime)
{ {
Super::Tick(DeltaTime); Super::Tick(DeltaTime);
UpdateHitNumbers();
} }
// Called to bind functionality to input // Called to bind functionality to input

View File

@ -42,6 +42,8 @@ protected:
UFUNCTION() UFUNCTION()
void DestroyHitNumber(UUserWidget* HitNumber); void DestroyHitNumber(UUserWidget* HitNumber);
void UpdateHitNumbers();
private: private:
/** Particles to spawn when hit by bullets */ /** Particles to spawn when hit by bullets */
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true)) UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = Combat, meta = (AllowPrivateAccess = true))
@ -103,5 +105,5 @@ public:
FORCEINLINE FString GetHeadBone() const { return HeadBone; } FORCEINLINE FString GetHeadBone() const { return HeadBone; }
UFUNCTION(BlueprintImplementableEvent) UFUNCTION(BlueprintImplementableEvent)
void ShowHitNumber(int32 Damage, FVector HitLocation); void ShowHitNumber(int32 Damage, FVector HitLocation, bool bHeadshot);
}; };

View File

@ -678,10 +678,12 @@ void AShooterCharacter::SendBullet()
if (BeamHitResult.BoneName.ToString() == HitEnemy->GetHeadBone()) if (BeamHitResult.BoneName.ToString() == HitEnemy->GetHeadBone())
{ {
damageToApply = EquippedWeapon->GetHeadshotDamage(); damageToApply = EquippedWeapon->GetHeadshotDamage();
HitEnemy->ShowHitNumber(damageToApply, BeamHitResult.Location, true);
} }
else else
{ {
damageToApply = EquippedWeapon->GetDamage(); damageToApply = EquippedWeapon->GetDamage();
HitEnemy->ShowHitNumber(damageToApply, BeamHitResult.Location, false);
} }
UGameplayStatics::ApplyDamage(HitEnemy, UGameplayStatics::ApplyDamage(HitEnemy,
@ -689,7 +691,6 @@ void AShooterCharacter::SendBullet()
GetController(), this, GetController(), this,
UDamageType::StaticClass()); UDamageType::StaticClass());
HitEnemy->ShowHitNumber(damageToApply, BeamHitResult.Location);
} }
} }
else else