PDA

View Full Version : Best method to turn on "affect selected object" on a per particle basis?


PerfectLine
09-19-2011, 05:29 PM
I want to set up a nParticle simulation that has an initial state (easy enough) and is affected by say a turbulence or gravity. BUT, I do not want the nParticles to be affected by the force until a collision object moves through them.

So I would have a turbulence in the scene but I want it to only affect the particles that have collided with an object.

Would a collision event be the best method? Something that turns the field "ON" on a per particle basis?

Or is this something that would be better made with a custom PP attribute?

Just seeing how people usually solve this. Would like to hear multiple ideas.

mandark1011
09-19-2011, 06:20 PM
id use the PP attribute method you mentioned, then you should be able to call the "event" and apply your PP magnitude.

Question. Why do you link to the DD, BSG sites? Are these places you have worked?

PerfectLine
09-19-2011, 06:25 PM
Yeah, actually, not sure why the links are there, I did want to list where I worked before but I'll have to check my user settings... I don't remember putting html links in it.. I work at DD but have worked at the other places in the past.

Duncan
09-19-2011, 08:54 PM
If you had multiple fields and such you would need separate attributes to control the magnitudePP for each. Instead you might try the following:
1. create the per particle attribute "collisionComponentId". This is -1 where there is no collision.
2. create a couple of custom per particle attributes
hasCollidedPP (float)
startPosition (vector)

Then for the particle system set up the following expressions:
Creation:
nParticleShape1.hasCollidedPP = false;
nParticleShape1.startPosition = nParticleShape1.position;


Runtime After Dynamics:

if( nParticleShape1.collisionComponentId != -1 ){
nParticleShape1.hasCollidedPP = true;
}
if( !nParticleShape1.hasCollidedPP ){
nParticleShape1.position = nParticleShape1.startPosition;
nParticleShape1.velocity = <<0,0,0>>;
}


The particles should then remain stationary until a collision.
(this is just off the top of my head... there is likely a simpler method)

PerfectLine
09-19-2011, 09:42 PM
Yeah, that works, is simple enough too. They become field activated on collision.

But, for some reason it is resetting my initial state. They no longer remember the initial state. I assume that is because startposition is not set per particle?

So the idea then would be to record the start position for all the particles in the vector right instead of setting it to 0,0,0? Which is happening in the creation expression?

EDIT--

Oh wait no, its the runtime expression in the startposition. Ah hah.

PerfectLine
09-19-2011, 09:57 PM
So it would be.... to stop the particles going to 0,0,0,

if( nParticleShape1.collisionComponentId != -1 ){
nParticleShape1.hasCollidedPP = true;
}
if( !nParticleShape1.hasCollidedPP ){
nParticleShape1.position = nParticleShape1.position0;
nParticleShape1.velocity = <<0,0,0>>;
}

BTW, THANKS DUNCAN. :D

Duncan
09-19-2011, 11:01 PM
Yeah... use position0 instead of a startPosition attribute if you are using initial state instead of emitted particles.

CGTalk Moderation
09-19-2011, 11:01 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.