Problem with SuggestProjectileVelocity

I am having problem using SuggestProjectileVelocity.
The output velocity doesn’t seems right to me.
Here is a clip I recorded on what happen https://youtu.be/4GcHQkqHGSM

The AI tank and Player tank has the same AimingComponent on them.
As you can see the projectile lands before the aiming point.
I have this code in my TankAimingComponent.cpp

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

auto AimDirection = OutLaunchVelocity.GetSafeNormal();
MoveBarrelTowards(AimDirection);

void UTankAimingComponent::MoveBarrelTowards(FVector AimDirection) {
	//work-out difference current barrel rotation, and AimDirection
	auto BarrelRotator = Barrel->GetForwardVector().Rotation();
	auto AimAsRotator = AimDirection.Rotation();
	auto DeltaRotator = AimAsRotator - BarrelRotator;

	//1 roll barrel up ,  -1 roll barrel down
	Barrel->Elevate(DeltaRotator.Pitch);
	Turret->Rotate(DeltaRotator.Yaw);
}

After getting OutLaunchVelocity. I use it on my barrel’s Pitch.

I have double checked my StartLocation/HitLocation/LaunchSpeed are at the right value.
And my ProjectileMovement’s blueprint setting on [Projectile Gravity Scale] is on 1.0

Wondering is there any other possible setting I mess up the OutLaunchVelocity value?

Here is my github: https://github.com/pzkwv/04_BattleTank2

Edit: I didn’t put the code in Tank.cpp, it’s actuallly in my TankAimingComponent.cpp

Hi, can you text what are you doing with OutLauchVelocity once you have it?

Hi MrMcKvarz, I have edited the post. After getting OutLaunchVelocity value. I have used it on my barrel’s Pitch. You can see the new edited code snippet inside of my post.

I didn’t get it aiming perfectly either, I thought it was due to barrel rotation restriction. Does your start location and projectile spawn location are the same?

Yes, my start location and projectile spawn location is the same.
That’s why I was wondering if it wasn’t c++ code’s problem.

um… some how I change the value on [Projectile Gravity Scale] from 1.0 to 0. It acts correctly now. But the tutorial video actually has it on 1.0…

I have the same problem :frowning:

See this link: Tutorial - Hitting Targets with Arching Projectiles in Unreal Engine - YouTube

Thank me later :slight_smile: