# Animation is too fast

I have an animation of a bullet but it seems to be going much faster than i was expecting.

I currently set it to 0.5 pixels per second yet it seems to be moving way over hundreads of pixels per second.

Not quite sure where my logic is going wrong:

This is inside my gameLoop which im using to calculate it:

var deltaTime = (new Date().getTime() - started) / 1000; // divide to get seconds
var position = deltaTime * bulletVelocity; //bulletVelocity is 0.5

var vectorX = destinationX - startX;
var vectorY = destinationY - startY;
var distance = Math.sqrt(vectorX * vectorX + vectorY * vectorY);

var x = startX + (vectorX * position);
var y = startY + (vectorY * position);

if (x < destinationX && y < destinationY) {
ctx2.drawImage(pulse, x, y); //draw the sprite on canvas
}


Have i got my logic wrong here i cannot work out why its moving so fast.

• You multiply the speed by the total distance to travel. That does not immediately make sense to me. You should comment your own code to explain what it is doing. The problem might become apparent if you try to express it explicitly. Dec 9 '13 at 1:41
• This question appears to be off-topic because it is about debugging your code for you. Dec 9 '13 at 1:41
• @SethBattin i multiply the timeElapsed which is deltaTime by velocity on line 2? Where am i multiplying distance by speed?
– Dave
Dec 9 '13 at 1:43
• var position = deltaTime * bulletVelocity; and var vectorX = destinationX - startX; and then var x = startX + (vectorX * position) Dec 9 '13 at 1:44
• @SethBattin so its the last two vars where my logic failed?
– Dave
Dec 9 '13 at 1:46