Posting the solution here. Life is complete!
void ATargetPawn::Fire(){
FVector Delta = this->GetActorLocation() - this->MainCannon->GetActorLocation();
FVector Gravity(0.0f, 0.0f, this->GetWorld()->GetGravityZ());
float MuzzleVelocity = 1024.0f;
float a = FVector::DotProduct(Gravity, Gravity);
float b = -4.0f * (FVector::DotProduct(Gravity, Delta) + MuzzleVelocity * MuzzleVelocity);
float c = 4.0f * FVector::DotProduct(Delta, Delta);
if (4.0f * a * c > b * b) {
LOG("Out of Bounds.");
return;
}
float Disc = FMath::Sqrt(b * b - 4.0f * a * c);
float MinTime = FMath::Sqrt((-b - Disc) / (2.0f * a));
FVector Result = (2.0f * Delta - Gravity * (MinTime * MinTime)) / (2.0f * MuzzleVelocity * MinTime);
//Spawn projectiles
FActorSpawnParameters Params;
Params.Owner = this->MainCannon;
Params.Instigator = this->Instigator;
AProjectile* const Projectile = this->GetWorld()->SpawnActor<AProjectile>(AProjectile::StaticClass(), this->MainCannon->GetActorLocation(), FRotator::ZeroRotator, Params);
if (Projectile){
//FVector LaunchDirection = RotatedResult.RotateVector(One);
Projectile->SetCutOffBoundary(this->GetActorLocation().Z);
Projectile->InitialVelocity(Result, 1.0f);
FRotator OppositeRoll = FRotator(0.0f, 0.0f, Result.Rotation().Pitch - 180.0f);
this->MainCannon->SetActorRotation(OppositeRoll);
}
}
Source code is provided below. Only the code is provided, no other contents/models/meshes, etc. File too large to attach.