# Calculate Distance Using Lifetime, Speed, and Time Between Ticks

I am trying to draw a line from the player to where he is facing, with the line being the distance his rockets will travel. I have ShipMissile.Speed, which is the number of pixels to move per tick, LastTick, the number of milliseconds between each call to Update(), and ShipMissile.Lifetime, which is the number of 10 ms ticks that the missile should be alive for. My current code is as follows:

``````Distance = (int)((ShipMissile.Speed * ((ShipMissile.Lifetime * 10) / LastTick)) * scale);
``````

`LastTick` is generally 16.6667 (I have never seen it vary from this value during testing), and for this particular missile type `Lifetime = 200`, which is 2000 ms, `Speed = 7`, and `scale = 1` ('native' game resolution).

The missile moves by using its rotation to generate a normalized vector, then multiplies by `Speed` and `scale` each game tick.

EDIT: Like this:

``````Missile.Position += direction * speed * scale;
``````

I am finding that the line is too short, and am wondering where the flaw in my code is (and please do not mention that I shouldn't be so dependent on frame rate or not be updating Lifetime outside of Update)? Is it even possible with my current (non optimal) setup? Thanks!

EDIT: I know this is kind of late, but here is a picture of what I mean (ignore the other stuff like the enemy and the score, etc):

-
Please clarify what you mean by, "The missile moves by using its rotation to generate a normalized vector, then multiplies by Speed and scale each game tick." – MickLH Sep 14 '13 at 6:49
@MickLH I am saying that in case how it moves makes a difference. In effect what I mean is that every tick that `ShipMissile.Lifetime > 0` the missile's position will update like so: `ShipMissile.Position += Velocity * scale`, where `Velocity` was calculated by using its rotation. Just in case that will change the distance travelled in any way (but I do not believe it will.) – Mstr Ch33f Sep 14 '13 at 15:54
What's wrong with just increasing ShipMissile.Speed so it gets farther in the given lifetime? – David M Nov 7 '13 at 14:47
@DavidM Because the missiles are fine, I'm just trying to draw a line that is the same length as their travel time. I just cannot get the line to be as long as the travel time. Making the missiles go faster would make the line longer, but the ratio would (should?) remain the same, so it would still be too short. – Mstr Ch33f Nov 16 '13 at 5:09

Also, `direction * scale * speed` is missing `lastTick`, assuming the speed is not expressed as "distance per tick" but in terms of an actual time unit (distance per second). Which it should.