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
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):