Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

aker_jus

Particle system update problem..

This topic is 5565 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

Hello, for some reason, all the particles in my particle system move all at once, each position is the same as every other. it looks like a dot moving to the right. This is my update code:
HRESULT CRTParticleSystem::Update (float timer)
{
	if (!inst.bCreated)
		return RT_FAIL;

	vector<RTParticle>::iterator pParticle;

	inst.CurrentTime += timer;

	float TimeElapsed = 0.0f;

	for (pParticle=inst.pParticles.begin(); pParticle!=inst.pParticles.end(); pParticle++)
	{
        if (pParticle->Active)
		{
			TimeElapsed = inst.CurrentTime - (*pParticle).CreationTime;

	        (*pParticle).pos = (*pParticle).oldpos + (*pParticle).vel * TimeElapsed;
			(*pParticle).oldpos = (*pParticle).pos;
			(*pParticle).vel = (*pParticle).oldvel + (*pParticle).CurrentGravity * TimeElapsed;
			(*pParticle).oldvel = (*pParticle).vel;
            (*pParticle).Life -= 0.001f;

			if ((*pParticle).Life <= 0)
			{
				(*pParticle).CreationTime = inst.CurrentTime;
                (*pParticle).Life = 1.0f;
				(*pParticle).Active = true;
				(*pParticle).pos = Position;
				(*pParticle).oldpos = Position;
				(*pParticle).vel = Velocity;
				(*pParticle).oldvel = (*pParticle).vel;
				(*pParticle).CurrentSize = SizeStart;
				(*pParticle).CurrentColor = ColorStart;
				(*pParticle).CurrentGravity = Gravity;
			}
		}
	}

	return RT_OK;
}
I kept trying to keep things simple for my first particle class, but it doesn''t seem to work.. I must be missing something here.

Share this post


Link to post
Share on other sites
Advertisement
It look''s to me like you are in the need of some randomness. As i see your Code all Particles that dies are beeing set to the
same position, velocity and liftetime. In my Particleengine these values are set to bee random within a given interval.

With the Init of the Particles i devine the Range in witch the Particles will be initialized. So my variables here are somthing like:

minLiftetime,maxLifetime
minXPos,maxXPos,minYPos,maxYPos,minZPos,maxZPos
minVelocity.X,maxVelocity.x ...

And in the initcode and where a particle will we respawnd the values for LiftTime,Velocity and Position will get some Randomization so they will fly with diferent Speed''s in different Directions.

NEHE has a got Tutorial on Particle Engines. He also uses Random-Values for Variables like StartingColor EndingColor, StartingSize and so on.. Mostly all Variables of a Particle get a random value assigned.

Think this should help you out a bit more.

Share this post


Link to post
Share on other sites
You''re updating the particles all by the same scalar value.

What you should do when you create the particle is this:

Set a velocity for the particle which is
v = base vel * variance factor

This will ensure that the particles don''t all move at the same veolcity; they will, however move in the same direction.

What you need to do then is generate a random number that can either be 1 or -1 and use that to make the initial velocity either positive or negative.

When you have done that, do as you have done and move them all by a fraction of this velocity over time

Oli


All the best problems start with C

Manta-X - A 3D arcade shoot-''em-up [In development]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!