I need to calculate X and Y speed for bullet (bullet will move every "update" by these), so i have following
public int[] getXandYSpeed(int pointOfOriginX, int pointOfOriginY, int aimToX, int aimToY){
int[] coords = new int[2];
aimToX = aimToX - pointOfOriginX;
aimToY = aimToY - pointOfOriginY;
while((aimToX + aimToY) > 5){
aimToX = aimToX/2;
aimToY = aimToY/2;
}
coords[0] = aimToX;
coords[1] = aimToY;
return coords;
But, this is not really accuare and bullet have like random speed(if final in final loop is aimToX plus AimToY equals 6 so (each is 3) so final speed will be x=1 and y=1, and if final loop equals four than it will end like x=2 and y=2, and thats making difference)
So, question is, how to make it better?