Quote: "Yeah I understand that, quite clever using squares like that so it is always a positive. Is that the only reason you used them, why not use ABS"
It's the distance formula without the sqrt. That's even what Hangar18 was using in the first example, that's also why I assumed the direction had already been taken care of in code we weren't given. It's always positive because the distance is always positive.
Quote: "What I meant was what if the bullet isn't going to hit the target but it's close enough that it could in the next iteration if it WAS going towards it. Sorry for the long winded explanation"
If you divide the distance to the target by the speed of the bullet and it's less than 1 (i.e. less than 1 iteration) it's an immediate hit. It depends on what you want to do. If the distance / speed came out to say 1.5, that means the bullet would reach the target before a complete 2nd iteration. So the target has only 1 iteration to get out of the way. So on the second iteration it's a hit if the target didn't move on the first iteration. If the dist/speed was 2.1, the target has 2 whole iterations to get out of the way. If it's not out of the way by the end of the 2nd iteration, it's a hit on the 3rd iteration.
It all depends on how one wants to handle it. You could truncate the decimal and just use the whole iteration numbers. 1.5 means a hit on the next iteration. 2.1 means a hit on the 2nd iteration from now. 4.7 means a hit on the 4th iteration. Or you could round the value. However you want to handle it.
If we aren't using collision, when it was the iteration that was supposed to be the time of the hit, compare the bullet position with the target position +- the target's size on each axis. Abs() would come in handy there. It's not a perfect system, but it's pretty quick and probably accurate enough.
For arguments sake, the direction of the bullet would be in 2d; assigning only 1 speed to the bullet:
it=dist#/bspd#
ang#=atanfull(ty-by,tx-bx)
bendx=newxvalue(bx,ang#,it*bspd#)
bendy=newzvalue(by,ang#,it*bspd#)
So after the iteration count, 'it', truncated, compare bendx and bendy with the target's new position.
Enjoy your day.