[Closed] pflow and script controller
I am encountering ‘strange’ results when using a script controller with a pflow.
The strange result sure have an obvious explanation, but I cannot find the way:
In the attached scene (max8) there I path constrained a point to a circle.
The percent-controller of the point is a script-operator that generates a pulsing movement.
There is also a pflow in the scene and its speedByIcon is parented to that point.
If the pflow is disabled both icon and point move like I expect them to move.
As soon as the pflow is enabled both start acting mad.
I guess I tracked this down to the upgrade steps of the pflow system.
The system is updating not in frame but subframe intervals.
Also the path percent switches from 0-100 to 0 to 1 if a script is attached to it.
I have the impression it switches to 0-??? if a pflow is active in the scene.
Can you maybe shed some light on this issue?
I will continue to try some combinations but someone could already have an explanation.
Georg
Georg,
Particle flow is history dependent, which means that if you put the timeslider on frame 50, it needs to evaluate the flow from frame 0 to frame 50. So in your case this means the script-controller gets executed 50 times. Since your script-controller calculates its value based on relative time, this obviously messes up its output.
I’ve modified your code so it uses absolute time values instead of relative. The first variable i defines the interval in which the helper moves/freezes, and the second variable s defines the movement per frame. In my example, the animation will loop at frame 200. I’m sure this script could be shortened/optimized, I just wrote it quickly so you have an idea. Uncomment the “format …” line to have the script print the p and q values to the listener (better turn off PFlow if you do this though).
Cheers,
Martijn
i = 10f -- move/freeze interval
s = .01 -- movement per frame
-- check in which "interval" current time lies
d = mod (F / i) 2
-- calculate movement value
p = ((d + ((F / (i*2)) as integer)) / i) * (s / .01)
-- calculate freeze value
q = ((((F / (i*2)) as integer)) + 1) * (s / .1)
-- format "p:%, q:%
" p q
-- set percent
if d < 1 then p else q
Martijn,
thanks for that explanaiton and the example.
If it is not possible to use the history-independent operators of box#3 it might be better to bake the movement before activating/adding pflow.
Anyway – this reminds me not to depend too much on this this.setConstant stuff. It is very handy – but as you showed it is possible to find forumulas for such tasks.
Georg