PDA

View Full Version : What am I doing wrong here?


noouch
12-26-2007, 12:03 PM
I'm pretty new to scripting, and at the moment I'm trying to get particles to spiral relative to their age with a script operator.

It works when the script looks like this:


on ChannelsUsed pCont do
(
pCont.useTime = true
pCont.useSpeed = true
pCont.useAge = true
)

on Init pCont do
(

)

on Proceed pCont do
(
count = pCont.NumParticles()
frameMult = 10
circleRadius = 0.03
spiralMult = 0.0001

for i in 1 to count do
(
circleTimeIndex = currentTime.frame
pCont.particleIndex = i
pCont.particleAge = 1
pCont.particleSpeed = [(sin(circleTimeIndex*frameMult))*(circleRadius-((circleTimeIndex)*spiralMult)), 0, (cos(circleTimeIndex*frameMult))*(circleRadius-((circleTimeIndex)*spiralMult))]
)
)

on Release pCont do
(

)


except for the fact that i'm using absolute time instead of particle age to drive it.
But whenever I replace the currentTime.frame value of the variable circleTimeIndex with pCont.particleAge, the whole script stops working.
Any idea what i'm doing wrong here?

Bobo
12-26-2007, 12:07 PM
Have you looked at the value of the Age channel (via Print)?
Time values inside of Particle Flow are generally in Ticks (4800 ticks per second) to ensure highest precision of calculations, while your current code uses frames. This might be the reason for the difference...
To convert ticks to frames, just divide the value by TicksPerFrame.

Also, in your current code you are setting particleAge to 1 in each loop, so the age would never change. Make sure you remove that line.

Finally, using currentTime inside a PFlow Scripted Operator is a bad idea - you should be using the local evaluation time range of the on Proceed handler - take a look at the default Birth Script operator which shows how this is done.

noouch
12-26-2007, 03:33 PM
Also, in your current code you are setting particleAge to 1 in each loop, so the age would never change. Make sure you remove that line.

Whoops, forgot to take that out before posting here. That was a troubleshooting line to see if particleAge even works, which it doesn't seem to, since an age test after the script operator still seems to be testing true after the given amount of frames.

Also, I think I found my main problem: I was using .particleAge when I should have been using something more like .particleAge.frame.

Now I have another problem though, that wasn't there when I was using currentTime: the first particle seems to go rogue, and I'm having trouble working out what's wrong with it... Just have a look at the screenshot and maybe the attached file Maybe I'll have to set the age to 0 manually for every particle when it enters the event.
This is what I have now:


on Proceed pCont do
(
count = pCont.NumParticles()
frameMult = 10
circleRadius = 0.025
spiralMult = 0.0005

for i in 1 to count do
(
circleTimeIndex = pCont.particleAge.frame
pCont.particleIndex = i
pCont.particleSpeed = [((sin(circleTimeIndex*frameMult))*circleRadius)/((circleTimeIndex+1)/10)*(((mod i 2)*2)-1), 0, ((cos(circleTimeIndex*frameMult))*circleRadius)/((circleTimeIndex+1)/10)]
)
)

noouch
12-26-2007, 06:03 PM
Never mind, working around it by killing off the first particle does the job good enough for me. I'd still be interested if anyone has an explanation for that weirdness though...

CGTalk Moderation
12-26-2007, 06:03 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.