Smol refactor

This commit is contained in:
Sara Montecino 2022-11-14 22:49:31 -08:00
parent f551802cef
commit c5018074c3
2 changed files with 10 additions and 39 deletions

View File

@ -154,22 +154,12 @@ void ABasePawn::shoot()
FRotator rotator(0, yaw.calculate_yaw(), 0); FRotator rotator(0, yaw.calculate_yaw(), 0);
if (use_aim_assist) if (use_aim_assist)
{ {
LogInfo(FString::Printf(TEXT("Yaw %f"), rotator.Yaw)); float assist_yaw;
const float y_offset = aim_assist(player_location, rotator); const bool succeess = aim_assist(player_location, rotator, assist_yaw);
if (y_offset != 0) 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); FVector forward = FRotationMatrix(rotator).GetUnitAxis(EAxis::X);
@ -195,7 +185,7 @@ void ABasePawn::shoot()
* *
* @return Yaw angle offset. * @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. * 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) if (!succeeded)
{ {
return 0; return false;
} }
ABasePawn* enemy_pawn = Cast<ABasePawn>(out_hit.Actor); ABasePawn* enemy_pawn = Cast<ABasePawn>(out_hit.Actor);
@ -238,31 +228,12 @@ float ABasePawn::aim_assist(const FVector start, const FRotator rotator)
if (!enemy_pawn) if (!enemy_pawn)
{ {
LogError("Aim assist trace hit non-pawn"); LogError("Aim assist trace hit non-pawn");
return 0; return false;
} }
const FVector enemy_vector = enemy_pawn->get_location() - start; const FVector enemy_vector = enemy_pawn->get_location() - start;
const FRotator new_rotator = enemy_vector.Rotation(); yaw_output = enemy_vector.Rotation().Yaw;
return false;
//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;
} }
void ABasePawn::handle_death() void ABasePawn::handle_death()

View File

@ -157,5 +157,5 @@ protected:
AActor* death_effect; AActor* death_effect;
private: private:
float aim_assist(const FVector start, const FRotator rotator); bool aim_assist(const FVector start, const FRotator rotator, float &yaw_output);
}; };