java - Moving an object towards a point android -



java - Moving an object towards a point android -

i have in initialization of bullet object:

x = startx; y = starty; double distance = math.sqrt(((endx - x) ^ 2) + ((endy - y) ^ 2)); speedx = (6 * (endx - x)) / distance; speedy = (6 * (endy - y)) / distance;

it goes touch on screen, farther away touch, faster goes. works fine on paper, i've tried different lengths , should work, bullets need move 6 pixels on line player point touched every step. , update method moves of course. why bullets move @ different speeds?

if remember java operators...

replace

double distance = math.sqrt(((endx - x) ^ 2) + ((endy - y) ^ 2));

with

double distance = math.sqrt(math.pow(endx - x, 2) + math.pow(endy - y, 2));

java android

Comments

Popular posts from this blog

javascript - mongodb won't find my schema method in nested container -

How do you set up a perforce server to work over the internet? -

ios - Lagging ScrollView with UIWebview inside -