#### Archived

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

# Particle system update problem..

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

## 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 on other sites
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:

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.

##### 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

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

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 13
• 9
• 12
• 9
• ### Forum Statistics

• Total Topics
631437
• Total Posts
3000063
×