Update AI for Improved Hit Detection & Projectiles

This commit is contained in:
Philip W 2024-02-29 02:57:55 +00:00
parent c7a52e42a5
commit 768d53549f
6 changed files with 14 additions and 10 deletions

Binary file not shown.

Binary file not shown.

View File

@ -20,16 +20,17 @@ EBTNodeResult::Type UBTTask_AttackPlayer::ExecuteTask(UBehaviorTreeComponent& Ow
{ {
if (const UBlackboardComponent* const Blackboard = OwnerComp.GetBlackboardComponent()) if (const UBlackboardComponent* const Blackboard = OwnerComp.GetBlackboardComponent())
{ {
FVector const Origin = AIController->GetPawn()->GetActorLocation(); USkeletalMeshComponent* const GunSKMesh = Cast<USkeletalMeshComponent>(AIController->GetPawn()->GetComponentsByTag(USkeletalMeshComponent::StaticClass(), "Gun")[0]);
FVector const Start = Origin + FVector(0.f, 0.f, 30.f); FVector const Origin = IsValid(GunSKMesh) ? GunSKMesh->GetComponentLocation() : AIController->GetPawn()->GetActorLocation() + FVector(0.f, 0.f, 30.f);
FVector const PlayerLocation = Blackboard->GetValueAsVector("TargetLocation"); FVector const Start = Origin;
FVector const End = Origin + AIController->GetPawn()->GetActorForwardVector() * 10000.f;
if (AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(AIController->GetPawn())) if (AEnemyCharacter* const EnemyCharacter = Cast<AEnemyCharacter>(AIController->GetPawn()))
{ {
EnemyCharacter->FireWeapon.Broadcast(); EnemyCharacter->FireWeapon.Broadcast();
EnemyCharacter->SetFiring(true); EnemyCharacter->SetFiring(true);
FCollisionQueryParams QueryParams; FCollisionQueryParams QueryParams;
QueryParams.AddIgnoredActor(AIController->GetPawn()); QueryParams.AddIgnoredActor(AIController->GetPawn());
if (FHitResult HitResult; GetWorld()->LineTraceSingleByChannel(HitResult, Start, PlayerLocation, ECC_Pawn, QueryParams)) if (FHitResult HitResult; GetWorld()->LineTraceSingleByChannel(HitResult, Start, End, ECC_Pawn, QueryParams))
{ {
if (IsValid(HitResult.GetActor())) if (IsValid(HitResult.GetActor()))
{ {