Hey Darkstorm,
Turns out ol’ Isaac “Apples Hurt” Newton can help you here. One of Newton’s kinetic equations is:
D = Vi * t + 1/2 * A * t * t
You know the distance (you have a start and end point), you know the time (assuming it’s constant), and you know the acceleration (gravity and some forward speed). Given all that, we can re-arrange this equation to get Vi.
Vi = (D - (0.5 * A * t * t)) / t
So, let’s start filling in some of those parameters.
// Let's just assume we have a "Launcher" actor which is where our arrow spawns from, and a "Target" which is just some 3D point in space.
const float arrowSpeed = 1.0f; // This is just some constant for our arrow acceleration. Since arrows don't have motors, just set this to 1.0f.
const float flightTime = 1.0f; // Reach our target in 1 second.
const FVector& arrowStart = Launcher->getActorLocation();
const FVector& arrowEnd = Target;
const FVector distanceVec = arrowEnd - arrowStart;
// Construct our acceleration. This assumes there's no Pitch/Roll to the "Launcher" actor.
const FVector& arrowDirection = Launcher->getActorRotation().Vector().SafeNormal();
const float gravity = GetWorld()->GetGravityZ();
const FVector acceleration(arrowDirection.X * arrowSpeed, arrowDirection.Y * arrowSpeed, gravity);
// Solve for Velocity
const FVector velocityInitial = (distanceVec - (0.5f * acceleration * flightTime * flightTime)) / flightTime;
// Apply the velocity to your arrow and away it goes!
I don’t have a sandbox setup to test this, but I’ve written similar code and this approach has worked well for me in the past - hopefully it’s what you’re looking for. Otherwise a quick google of “Projectile Motion” can give you numerous approaches and walkthroughs depending on the behavior you are looking for.
Good luck!