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