From c5018074c3fa552490dbb5f9f6d23b16a221ca1b Mon Sep 17 00:00:00 2001 From: Sara Montecino Date: Mon, 14 Nov 2022 22:49:31 -0800 Subject: [PATCH] Smol refactor --- Source/PresidentsBrigade/BasePawn.cpp | 47 +++++---------------------- Source/PresidentsBrigade/BasePawn.h | 2 +- 2 files changed, 10 insertions(+), 39 deletions(-) diff --git a/Source/PresidentsBrigade/BasePawn.cpp b/Source/PresidentsBrigade/BasePawn.cpp index c29b3bf..fca7886 100755 --- a/Source/PresidentsBrigade/BasePawn.cpp +++ b/Source/PresidentsBrigade/BasePawn.cpp @@ -154,22 +154,12 @@ void ABasePawn::shoot() FRotator rotator(0, yaw.calculate_yaw(), 0); if (use_aim_assist) { - LogInfo(FString::Printf(TEXT("Yaw %f"), rotator.Yaw)); - const float y_offset = aim_assist(player_location, rotator); - if (y_offset != 0) + float assist_yaw; + const bool succeess = aim_assist(player_location, rotator, assist_yaw); + if (assist_yaw) { - rotator.Yaw = y_offset; + rotator.Yaw = assist_yaw; } - LogInfo(FString::Printf(TEXT("Offset %f"), y_offset)); - FVector line_end = FVector(5000, 0, 0); - FVector aim_line_end = rotator.RotateVector(line_end); -// DrawDebugLine( -// GetWorld(), -// player_location, -// aim_line_end + player_location, -// FColor::Red, -// true -// ); } FVector forward = FRotationMatrix(rotator).GetUnitAxis(EAxis::X); @@ -195,7 +185,7 @@ void ABasePawn::shoot() * * @return Yaw angle offset. */ -float ABasePawn::aim_assist(const FVector start, const FRotator rotator) +bool ABasePawn::aim_assist(const FVector start, const FRotator rotator, float &yaw_output) { /* * Create trace end based on start location and given rotator. @@ -228,7 +218,7 @@ float ABasePawn::aim_assist(const FVector start, const FRotator rotator) */ if (!succeeded) { - return 0; + return false; } ABasePawn* enemy_pawn = Cast(out_hit.Actor); @@ -238,31 +228,12 @@ float ABasePawn::aim_assist(const FVector start, const FRotator rotator) if (!enemy_pawn) { LogError("Aim assist trace hit non-pawn"); - return 0; + return false; } const FVector enemy_vector = enemy_pawn->get_location() - start; - const FRotator new_rotator = enemy_vector.Rotation(); - - //FVector target_vector = FVector(enemy_vector.X, enemy_vector.Y, 0); - //target_vector.Normalize(); - - //FVector actual_vector = FVector(trace.X, trace.Y, 0) - start; - //actual_vector.Normalize(); - - //const float angle_between = UKismetMathLibrary::DegAcos(FVector::DotProduct(actual_vector, target_vector)); - //const FVector cross = FVector::CrossProduct(actual_vector, target_vector); - //if (cross.Z > 0) - //{ - // return angle_between; - //} - //else if (cross.Z < 0) - //{ - // return angle_between * -1; - //} - - //return 0; - return new_rotator.Yaw; + yaw_output = enemy_vector.Rotation().Yaw; + return false; } void ABasePawn::handle_death() diff --git a/Source/PresidentsBrigade/BasePawn.h b/Source/PresidentsBrigade/BasePawn.h index d278d3b..c7ee815 100755 --- a/Source/PresidentsBrigade/BasePawn.h +++ b/Source/PresidentsBrigade/BasePawn.h @@ -157,5 +157,5 @@ protected: AActor* death_effect; private: - float aim_assist(const FVector start, const FRotator rotator); + bool aim_assist(const FVector start, const FRotator rotator, float &yaw_output); };