1
\$\begingroup\$

Hi I'm having troubles off setting particles from a point of origin. I want my particles to spread out after a certain radius from a the point of origin. For example, this is what I have right now:

enter image description here

All particles emitted from a point of origin. What I want is this:

enter image description here

Particles are offset from the point of origin by some amount, i.e after the circle. What is the best way to achieve this? At the moment, I have the point of origin, the position of each particle and its rotation angle. Sorry for the poor illustrations.


Edit: I was mistaken, when a particle is created, I have only the point of origin. When the particle is created I am able to calculate the rotation of the particle in the update method after it has moved to a new location using atan2() method.

This is how I create/manage particles: Created new particle at enemy ship death location, for every new particle which is added to the list, call Update and Draw to update its position, calculate new angle and draw it.

\$\endgroup\$

2 Answers 2

2
\$\begingroup\$

First convert the angle to a normalized direction vector. You could try using the following method (taken from here). I think the order of the Sin and Cos and the signs might depend on how your angle is defined (e.g. what direction 0 represents), so play around with them if the result seems wrong:

Vector2 AngleToVector(float angle)
{
    return new Vector2((float)Math.Sin(angle), -(float)Math.Cos(angle));
}

Then multiply it by the radius of the circle and add it to the point of origin to get the starting position of the particle. In other words:

Vector2 origin; // center of the circle
float radius; // radius of the circle
float angle; // random value from 0 to 2PI
Vector2 startPosition = origin + AngleToVector(angle) * radius;
\$\endgroup\$
3
  • \$\begingroup\$ See my edits, when I use the code you described to create a new particle, nothing new happens. When I use your code in the Draw method of my particle, it forms a nice circle(until they die off). \$\endgroup\$
    – Sun
    Commented Sep 10, 2012 at 0:32
  • \$\begingroup\$ After playing around with this, I was able to get it to work. To get the angle of each particle, I just offset the point of emission by the particles velocity to find out where the particle would be in the future and then use atan2() to calculate its angle and then used your example to find out the new starting position for each particle. \$\endgroup\$
    – Sun
    Commented Sep 10, 2012 at 11:17
  • \$\begingroup\$ @Sun If you already have a velocity vector pointing in the right direction, there's no need to calculate the angle! Simply replace AngleToVector(angle) above with Vector2.Normalize(velocity). \$\endgroup\$ Commented Sep 10, 2012 at 12:00
0
\$\begingroup\$

Alternatively, you could leave your code unchanged from your 1st example where they all start from a common origin (enemy ship location).

Then add a toggle that simply sets (renders) them transparent until they are a set distance from that origin.

\$\endgroup\$
1
  • \$\begingroup\$ This is one thing that I tried, the problem here is that it looks as if there is a delay between the enemy's death and the explosion. Another way round it is having the particles velocity increase rapidly at the start and die down later, this leads to a cool effect. \$\endgroup\$
    – Sun
    Commented Sep 10, 2012 at 11:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .