PDA

View Full Version : Tryomg to make a forcefield


Dragons0088
01-23-2010, 08:17 AM
Hey guys,

This is my first attempt ever at using MEL to do something. My goal is to make some particles hit an object and every time they hit the object it changes the transparency of the object like a forcefield in a way. I have written this much and made it to the Run After Dynamics on the ParticleShape. Do you know why its not working? Am I approaching this wrong? BTW HailShape is my particle shape, event is the collision test and lambert2 is the material on the forcefield.


if (HailShape.event == 1)
{
float $Rand=rand (1);
setAttr lambert2.transparencyR $Rand;
setAttr lambert2.transparencyG $Rand;
setAttr lambert2.transparencyB $Rand;
}

else
{
setAttr lambert2.transparencyR 0;
setAttr lambert2.transparencyG 0;
setAttr lambert2.transparencyB 0;
}

rahulsg2901
01-23-2010, 09:39 AM
If you are using expression then if (HailShape.event == 1) its works. But you are using MEL then before assigning in the condition you must get attribute. So code is


float $value =` getAttr "HailShape.event" `;

if ($value == 1)
{
float $Rand=rand (1);
setAttr lambert2.transparencyR $Rand;
setAttr lambert2.transparencyG $Rand;
setAttr lambert2.transparencyB $Rand;
}
else
{
setAttr lambert2.transparencyR 0;
setAttr lambert2.transparencyG 0;
setAttr lambert2.transparencyB 0;
};

Dragons0088
01-25-2010, 01:04 AM
Thank you for your quick response. I guess I was using expressions in the end anyway. For some reason my script doesnt work. I think it has something to do with the if command for the .event?

Aikiman
01-27-2010, 09:55 PM
Excuse my deleted post but what is not working? Using your code changes the transparency of your shader.

The probem i see is that while event is equal to 1 and your p[article is still alive, then the shader's transparency will change every frame until event changes or the particle dies. I would instead create a collisionU pp attribute and test whether it is greater than zero instead of using event. If you turn on numeric particles you can see how the collisionU works.

Actually the event call does work but you have to kill the particle in the expression using lifespanPP==0 at the end of your expression rather than killing it in the event editor. The event editor kills the particle before it evaluates the expression.

Aikiman
01-27-2010, 11:40 PM
mmmm, this doesnt seem to work with more than one particle in existance at one time.

CGTalk Moderation
01-27-2010, 11:40 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.