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

enter image description here

How can i calulate a valid range (RED) for my object's (BLACK) traveling direction (GREEN). The green is a Vector2 where x and y range is -1 to 1.

What I'm trying to do here is to create rocket fuel burn effekt. So what i got is

  • rocket speed (float)
  • rocket direction (Vector2 x = [-1, 1], y = [-1, 1])

I may think that rocket speed does not matter as fuel burn effect (particle) is created on position with its own speed.

share|improve this question

You need a normal vector for your rocket direction. You can use cross product to calculate it, which in 2D results to normal = vector(direction.y, -direction.x);

Now the burn vector is just a normalized linear combination of -direction and normal. E.g.

float k = random() * 0.3;
burn = normalize(normal * k - direction * (1 - k));
share|improve this answer

I'd suggest you calculate the polar angle (angle with the X axis) of the vector. Then you can rotate it by 180° and for each particle add a randomized value based on the width of the burn effect cone (e.g. +/- 30°). Then convert the angle back to vector.

Here's some C# example code to add a PolarAngle property to a Vector2D class. Note that it's operating in Radian not Degree.

 * An angle describing the orientation of the Vector. (-1,0) is 0. (1,0) is Pi. 
public double PolarAngle
        return Math.Atan2(Y, X) + Math.PI;

        double len = Length;
        X = len * Math.Cos(value);
        Y = len * Math.Sin(value);
share|improve this answer

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.