SuggestProjectileVelocity doesn't work with AI Controller

Hi brothers !! :slight_smile:

bool bHaveAimSolution = UGameplayStatics::SuggestProjectileVelocity
	(
		this,
		LaunchVelocity,
		StartLocation,
		HitLocation,
		LaunchSpeed,
		ESuggestProjVelocityTraceOption::DoNotTrace,
	);

The previous code doesn’t work for AI Controller, Can any one explain the problem !!?

Have you added logs to see if the AI is even calling that function?

Have you added logs to see if the AI is even calling that function?

UE 4.22

Of course, I did !!

TankPlayer Name is Tank_BP_C_0
TankAI Name is Tank_BP_2

void UTankAimingComponent::AimAt(FVector HitLocation, float LaunchSpeed)
{
	if (!Barrel) { return; }

	FVector OUT LaunchVelocity;
	FVector StartLocation = Barrel->GetSocketLocation(FName("Projectile"));

	bool bHaveAimSolution = UGameplayStatics::SuggestProjectileVelocity
	(
		this,
		LaunchVelocity,
		StartLocation,
		HitLocation,
		LaunchSpeed,
		ESuggestProjVelocityTraceOption::DoNotTrace
	);

	if (bHaveAimSolution)
	{
		auto TankName = GetOwner()->GetName();
		auto AimDirection = LaunchVelocity.GetSafeNormal();
		UE_LOG(LogTemp, Warning, TEXT("*** Tank Name is %s, AimDirection is %s"), *TankName, *AimDirection.ToString());
	}
}

1

I said the AI. You just logged this in the AimingComponent and by the looks of it the AI isn’t calling that function.
Does the tank in your level have the TankAIController attached to it? When you play the level do you see it in the world outliner?

Ok, I added the next code inside UTankAimingComponent::AimAt and before the bHaveAimSolution condition !!

auto TankName = GetOwner()->GetName();
UE_LOG(LogTemp, Warning, TEXT("*** Tank Name is %s"), *TankName);

Full Code …

void UTankAimingComponent::AimAt(FVector HitLocation, float LaunchSpeed)
{
	if (!Barrel) { return; }

	FVector OUT LaunchVelocity;
	FVector StartLocation = Barrel->GetSocketLocation(FName("Projectile"));

	auto TankName = GetOwner()->GetName();
	UE_LOG(LogTemp, Warning, TEXT("*** Tank Name is %s"), *TankName);

	bool bHaveAimSolution = UGameplayStatics::SuggestProjectileVelocity
	(
		this,
		LaunchVelocity,
		StartLocation,
		HitLocation,
		LaunchSpeed,
		ESuggestProjVelocityTraceOption::DoNotTrace
	);

	if (bHaveAimSolution)
	{
		auto TankName = GetOwner()->GetName();
		auto AimDirection = LaunchVelocity.GetSafeNormal();
		UE_LOG(LogTemp, Warning, TEXT("*** Tank Name is %s, AimDirection is %s"), *TankName, *AimDirection.ToString());
	}
}

Look at the Logout
2

And what’s your launch speed? I assume it’s just that it’s too far away to be able to find a solution to hit your tank.

And what’s your launch speed? I assume it’s just that it’s too far away to be able to find a solution to hit your tank.

float LaunchSpeed = 100000;

Oh wait, you’re missing arguments.

bool bHaveAimSolution = UGameplayStatics::SuggestProjectileVelocity
(
    this,
    LaunchVelocity,
    StartLocation,
    HitLocation,
    LaunchSpeed,
    ///////
    false, 
    0,
    0,
    ///////
    ESuggestProjVelocityTraceOption::DoNotTrace
);
1 Like

Thank @DanM for your answer :slight_smile:

To be honest, i arrived to that solution that you show before asking this question, but the problem i faced is Why Mr @ben remove these arguments from the function !!

It was done by mistake. Ben corrects it later.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms