Help with calculating projectile shot

local function GetPredictedPosition(targetPosition, targetVelocity, projectileSpeed, shooterPosition, shooterVelocity, gravity)
	local distance = (targetPosition - shooterPosition).Magnitude

	local p = targetPosition - shooterPosition
	local v = targetVelocity - shooterVelocity
	local a = Vector3.new()

	local timeTaken = (distance / projectileSpeed)

	if gravity > 0 then
		local timeTaken = projectileSpeed/gravity+math.sqrt(2*distance/gravity+projectileSpeed^2/gravity^2)
	end

	local goalX = targetPosition.X + v.X*timeTaken + 0.5 * a.X * timeTaken^2
	local goalY = targetPosition.Y + v.Y*timeTaken + 0.5 * a.Y * timeTaken^2
	local goalZ = targetPosition.Z + v.Z*timeTaken + 0.5 * a.Z * timeTaken^2

	return Vector3.new(goalX, goalY, goalZ)
end

This makes the archer shoot to high. I’m using FastCast for this.

local orgin = firePoint.WorldPosition
	local direction = (hitPosition - orgin + Vector3.new(0,ToolData.LaunchHeight,0)).Unit
	caster:Fire(orgin, direction, ToolData.BulletSpeed, castBehavior)

The code was from: Projectile shot calculations - #30 by koziahss