Updated RTCombat for Shooting Accuracy via LineTrace
This commit is contained in:
parent
1751ffd163
commit
6a041e4621
BIN
Content/BlueprintAI/AI/BTT_ChaseBruh.uasset
(Stored with Git LFS)
BIN
Content/BlueprintAI/AI/BTT_ChaseBruh.uasset
(Stored with Git LFS)
Binary file not shown.
BIN
Content/Blueprints/Combat_UI/CombatCharacterRT.uasset
(Stored with Git LFS)
BIN
Content/Blueprints/Combat_UI/CombatCharacterRT.uasset
(Stored with Git LFS)
Binary file not shown.
@ -22,9 +22,9 @@ ARealTimeCombat::ARealTimeCombat()
|
|||||||
|
|
||||||
void ARealTimeCombat::StartCombat()
|
void ARealTimeCombat::StartCombat()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (HUD->IsInViewport()) return;
|
if (HUD->IsInViewport()) return;
|
||||||
HUD->AddToViewport();
|
HUD->AddToViewport();
|
||||||
|
bStartTimer = true;
|
||||||
//EnemyActor = Enemy;
|
//EnemyActor = Enemy;
|
||||||
|
|
||||||
// if (APlayerController* PC = Cast<APlayerController>(GetWorld()->GetFirstPlayerController()))
|
// if (APlayerController* PC = Cast<APlayerController>(GetWorld()->GetFirstPlayerController()))
|
||||||
@ -116,6 +116,12 @@ void ARealTimeCombat::BeginPlay()
|
|||||||
EnemyActor = Cast<AActor>(Actor);
|
EnemyActor = Cast<AActor>(Actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UGameplayStatics::GetAllActorsOfClassWithTag(GetWorld(), AActor::StaticClass(), FName("Player"), AllCharacterActorsInScene);
|
||||||
|
for (AActor* Actor : AllCharacterActorsInScene)
|
||||||
|
{
|
||||||
|
PlayerActor = Cast<AActor>(Actor);
|
||||||
|
}
|
||||||
|
|
||||||
HUD = CreateWidget<UUserWidget>(GetWorld(), HUDWidget);
|
HUD = CreateWidget<UUserWidget>(GetWorld(), HUDWidget);
|
||||||
|
|
||||||
CurrentComboTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("CurrentCombo"));
|
CurrentComboTextBlock = Cast<UTextBlock>(HUD->GetWidgetFromName("CurrentCombo"));
|
||||||
@ -158,6 +164,12 @@ void ARealTimeCombat::ExecuteCast(FString Combo)
|
|||||||
RevertActionPoints();
|
RevertActionPoints();
|
||||||
UpdateActionPoints();
|
UpdateActionPoints();
|
||||||
|
|
||||||
|
if (!HitEnemy())
|
||||||
|
{
|
||||||
|
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Missed"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
switch (bIsPlayerTurn)
|
switch (bIsPlayerTurn)
|
||||||
{
|
{
|
||||||
case true:
|
case true:
|
||||||
@ -231,9 +243,7 @@ void ARealTimeCombat::UpdateProgressBars() const
|
|||||||
void ARealTimeCombat::Tick(float DeltaSeconds)
|
void ARealTimeCombat::Tick(float DeltaSeconds)
|
||||||
{
|
{
|
||||||
Super::Tick(DeltaSeconds);
|
Super::Tick(DeltaSeconds);
|
||||||
UE_LOG(LogTemp, Warning, TEXT( "%f" ), DeltaSeconds);
|
if (ActionPointsTimer >= 1.0f && HeldActionPoints < MaxActionPoints && bStartTimer)
|
||||||
//Every second add 1 action point
|
|
||||||
if (ActionPointsTimer >= 1.0f && HeldActionPoints < MaxActionPoints)
|
|
||||||
{
|
{
|
||||||
HeldActionPoints += 1;
|
HeldActionPoints += 1;
|
||||||
ActiveActionPoints += 1;
|
ActiveActionPoints += 1;
|
||||||
@ -288,3 +298,22 @@ void ARealTimeCombat::UpdateResourceBars() const
|
|||||||
IronResourceBar->SetPercent(IronResource / 10.0f);
|
IronResourceBar->SetPercent(IronResource / 10.0f);
|
||||||
SulfurResourceBar->SetPercent(SulfurResource / 10.0f);
|
SulfurResourceBar->SetPercent(SulfurResource / 10.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ARealTimeCombat::HitEnemy() const
|
||||||
|
{
|
||||||
|
FHitResult HitResult;
|
||||||
|
FVector Start = PlayerActor->GetActorLocation();
|
||||||
|
FVector End = PlayerActor->GetActorForwardVector() * 1000.0f + Start;
|
||||||
|
FCollisionQueryParams CollisionParams;
|
||||||
|
CollisionParams.AddIgnoredActor(PlayerActor);
|
||||||
|
if (GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECC_Pawn, CollisionParams))
|
||||||
|
{
|
||||||
|
DrawDebugLine(GetWorld(), Start, End, HitResult.bBlockingHit ? FColor::Green : FColor::Red, false, 5.0f, 0, 10.0f);
|
||||||
|
if (HitResult.GetActor() == EnemyActor)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
DrawDebugLine(GetWorld(), Start, End, HitResult.bBlockingHit ? FColor::Green : FColor::Red, false, 5.0f, 0, 10.0f);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
@ -28,7 +28,8 @@ class THE_TWILIGHT_ABYSS_API ARealTimeCombat : public AGameStateBase
|
|||||||
UPROPERTY(EditDefaultsOnly)
|
UPROPERTY(EditDefaultsOnly)
|
||||||
int SulfurResource = 10; // W
|
int SulfurResource = 10; // W
|
||||||
|
|
||||||
// AActor* PlayerActor;
|
UPROPERTY(VisibleAnywhere)
|
||||||
|
AActor* PlayerActor;
|
||||||
UPROPERTY(VisibleAnywhere)
|
UPROPERTY(VisibleAnywhere)
|
||||||
AActor* EnemyActor;
|
AActor* EnemyActor;
|
||||||
// AActor* ActiveActor;
|
// AActor* ActiveActor;
|
||||||
@ -120,4 +121,7 @@ private:
|
|||||||
void ClearBattleLog();
|
void ClearBattleLog();
|
||||||
void UpdateBattleLog();
|
void UpdateBattleLog();
|
||||||
void UpdateResourceBars() const;
|
void UpdateResourceBars() const;
|
||||||
|
bool HitEnemy() const;
|
||||||
|
|
||||||
|
bool bStartTimer = false;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user