PDA

View Full Version : collisionNormal to kill particle?

 destruct00710-06-2009, 08:54 PMAnyone know a way to kill a particle if it hits the inverted normal of a surface? Basically I have a scene where I need the debris particles to collide with a bunch of things, but they also enter into the character. I was wondering if it's possible to use the collision attr collisionNormal to kill the particles if they ever hit the inverted normal of a surface (the inside of my character)
rxgeez
10-06-2009, 11:02 PM
you could try assigning a black texture to one side of the object and white to the other then use colorAtPoint...maybe something like this....I think this would work:

//runtime expression
if (particleShape1.collisionU != -1){

float \$colorU = particleShape1.collisionU;
float \$colorV = particleShape1.collisionV;

//colorAtPoint
vector \$colorAtPoint = `colorAtPoint -o RGB -u \$colorU -v \$colorV ramp1`;

if (\$colorAtPoint != <<1, 1, 1>>){
particleShape1.lifespanPP = 0;
}
}

good luck

-k

stooch
10-07-2009, 03:38 AM
Anyone know a way to kill a particle if it hits the inverted normal of a surface?

Basically I have a scene where I need the debris particles to collide with a bunch of things, but they also enter into the character. I was wondering if it's possible to use the collision attr collisionNormal to kill the particles if they ever hit the inverted normal of a surface (the inside of my character)

the solution is to use a higher collision offset/thickness, more substeps, etc to fix this instead of writing slow expressions.

if you dont want an offset, you create a new collision shape and then use transform component along normal to shrink your collider down and then increase collision offset/thicknes. this greatly speeds up sim and reduces collision errors during fast movement.

ie, if your thickness is at .3 then your particle would have to travel over .3 units PER STEP to escape collision. so if you have 10 substeps, that means that the particle would have to cover 3 units in one frame to evade collision...

homedog
10-07-2009, 05:22 AM
there is a per particle attribute named "collisionNormal",add it to the particle,then when a particle is colliding on a surface,it's "collisionNormal" will be <<0,1,0>> or <<0,-1,0>>,you can kill the particle depending on this.

edit: i just found that you have seen the attribute "collisionNormal",and the value of it is not that simple....it changes in many different ways when your model is not just a freezed poly sphere.need more test to find the regular.

stooch
10-07-2009, 03:41 PM
again.... doing this with scripts is aBAAAAD idea. scripts are SLOW.

besides, if you have problems detecting collisions with the front face, what makes you all think that you wont have problems with the rear face? the root of the problem is expressed above...

there is a per particle attribute named "collisionNormal",add it to the particle,then when a particle is colliding on a surface,it's "collisionNormal" will be <<0,1,0>> or <<0,-1,0>>,you can kill the particle depending on this.

edit: i just found that you have seen the attribute "collisionNormal",and the value of it is not that simple....it changes in many different ways when your model is not just a freezed poly sphere.need more test to find the regular.

homedog
10-08-2009, 05:25 AM
edit:expression below does't work...failed.

expression could be writen like this:
"last_pos" is a new vector pp attribute which store the position of previous frame.
creation:
particleShape1.last_pos=particleShape1.position;

runtime:
\$vel=particleShape1.position-particleShape1.last_pos;
if(\$angle>90)
particleShape1.lifespanPP=0;
particleShape1.last_pos=particleShape1.position;

homedog
10-09-2009, 03:59 PM
i try it on another way,and it seems work...when your model which you want your particle collide on is freezed...you can try this:

runtime expression:
----"collisionInVelocityReverse" is a new customer vector pp attribute.
----"pSphere1" is the poly model to collide on.
if(mag(particleShape1.collisionIncomingVelocity)<1730)
particleShape1.collisionInVelocityReverse=-particleShape1.collisionIncomingVelocity;
if(particleShape1.collisionComponentId>0)
{
int \$id=particleShape1.collisionComponentId;
string \$obj="pSphere1"+".f["+\$id+"]";
string \$normalString[]=`polyInfo -fn \$obj`;
string \$result[];
int \$num=`tokenize \$normalString[0] " " \$result`;
float \$xx=\$result[2];
float \$yy=\$result[3];
float \$zz=\$result[4];
vector \$collidingFaceNormal=<<\$xx,\$yy,\$zz>>;

if(\$angle>90)
{
particleShape1.lifespanPP=0;
}
}

Maybe something wrong...but we can keep approaching it.

Aikiman
10-28-2009, 01:32 AM
vector \$col = particleShape1.collisionNormal;
if (\$col.y == -1)
particleShape1.lifespanPP=0;

CGTalk Moderation
10-28-2009, 01:32 AM
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.