So, it always misses because it is shooting where is the target right now.
I suggest that you should get the target velocity and then do math that calculates the position it will be in 2 or how many seconds. This only works if the target’s future path is interrupted by its movement.
this code is adding velocity of the object multiplied by distance divided by projectile speed to object position. it is trying to shoot at target’s future position. but its not working