Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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
add comment

2 Answers 2

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
add comment

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
{
    get
    {
        return Math.Atan2(Y, X) + Math.PI;
    }

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

Your Answer

 
discard

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.