Jump to content
  • Advertisement
Sign in to follow this  
Min0

particles spreading

This topic is 2556 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 :


examplee.png


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

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

example2c.png

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


Link to 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


Link to 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:

exampl3.png

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!