• Advertisement

# particles spreading

This topic is 2380 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

I am building a particle system and my current problem is with spread angle.

I'm not using Vectors, instead I have 2 coordinates.

In initialization phase I m doing:
 float angle = random.Next(0,90); parts.Angle_X = AngleToVector(angle)[0]; parts.Angle_Y = AngleToVector(angle)[1]; 

and this the way I m getting vector from angle:

private float[] AngleToVector(float angle) { //vector[0] = X; //vector[1] = Y; float[] vector = new float[2]; vector[0] = (float)Math.Cos(angle); vector[1] = (float)Math.Sin(angle); return vector; } 

I update my particles position:

 parts.Position_X += parts.Angle_X * parts.Velocity; parts.Position_Y += parts.Angle_Y * parts.Velocity;

what I get after this is :

particles are spread not from 0 till 90 but all over the screen.

When I m using random.nextDouble() I m getting spread angle:

How can I control the angle, so when angle is from 0 to 90 it would be upper right square, from 90 to 180 - upper left and so on?

#### Share this post

##### Share on other sites
Advertisement
You need to supply Sin and Cos with an angle in radians. I think you can do MathHelper.ToRadians(float degree) in XNA.

Edit:

And you probably want to do:

 float vector[2] = AngleToVector(angle); 

Instead of calling AngleToVector() twice. Not sure if the compiler optimize the duplicate call somehow tho.

#### Share this post

##### Share on other sites

You need to supply Sin and Cos with an angle in radians. I think you can do MathHelper.ToRadians(float degree) in XNA.

Edit:

And you probably want to do:

 float vector[2] = AngleToVector(angle); 

Instead of calling AngleToVector() twice. Not sure if the compiler optimize the duplicate call somehow tho.

It's perfect!
exactly what I wanted. Solution was using radians 8-)
Oh, and calling twice AngleToVector() didn't matter, it gave me the same results doing both ways.

p.s. I m suppose to build this without using XNA so to get radians I used:
double radians = (Math.PI / 180) * angle;

and the result:

#### Share this post

##### Share on other sites
Excellent! I'm glad it worked.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement
• ### Popular Tags

• Advertisement
• ### Popular Now

• 24
• 11
• 17
• 11
• 13
• Advertisement