Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

What I mean by the line not being long enough

share|improve this question
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

How short is it compared to the real length?

Does it happen if the ship is stationary?

You're casting to int. Maybe you're accumulating rounding errors in the missile moving code, especially if you do it incrementally?

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.

I believe this is too high level to be concerned about scale. Compute everything in "world coordinates" and worry about the scale only when you draw.

share|improve this answer
When moving the missile, I don't cast to int, so I don't think that should accumulate rounding errors there, although it is done incrementally per tick. I am using scale because movement speed is scaled, so the line's length must also be scaled. The picture should answer the first question, and the line never changes length, no matter which way I move or which direction I face. – Mstr Ch33f Nov 16 '13 at 17:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.