PDA

View Full Version : moving objects using PFlow script


Anton980
06-07-2011, 01:47 PM
Hello everyone! I am currently working on a traffic control set up using PFlow that involves a traffic light and a deflector to stop traffic or let it through.

Below is a screenshot of the current setup for the traffic light as well as one of the scripts.

http://farm6.static.flickr.com/5316/5808299732_f78be64cb5_b.jpg

The script for "red light" is identical, except for the coordinates

The deflector's position is controlled by 2 scripts inside the PFlow for the traffic light - when the "green light" event begins, the deflector is given coordinates of 0,0,-50 and is moved out of the traffic's way. Then when the red light event is triggered, a very similar script places the deflector back to 0,0,0

For some reason the scripts conflict with each other. The deflector moves to 0,0,-50 as soon as green light comes on, but only stays at those coordinates for one frame, after which it moves back to 0,0,0. If I disable the "red light" script - the deflector moves at a right time and stays at a right place.

Could anyone tell me what I'm doing wrong? Thank you very much!

JohnnyRandom
06-07-2011, 06:20 PM
I would setup some type of check. As it is you are just saying move without giving it a reason to move. I think things like to move better when they have a reason :)

This will work, move the Set Array to the global node (PF traffic light event) and then just flip the then/else in the deflector down script op (so the test is the opposite)


on Proceed pCont do
(
theCount = pCont.numParticles() --Get the current Particle count

for i in 1 to theCount do
(
pCont.particleIndex = i --assign an index
particleState = pCont.isParticleNew i --check to see if particle has arrived

if particleState == True then -- Particles State? move the deflector
(
Traffic.pos = [0,0,0]
format "--Up-- %\n" Traffic[i].pos
)
else
(
Traffic.pos = [0,0,-50]
format "--Down-- %\n" Traffic[i].pos
)
)

)

Anton980
06-07-2011, 07:30 PM
This is excellent! Thank you very much!

What does the line "format "--Up-- %\n" Traffic[i].pos" do?

JohnnyRandom
06-07-2011, 08:09 PM
np :)


What does the line "format "--Up-- %\n" Traffic[i].pos" do?

It just prints "--Up--" or "--Down--" respectively and the position of the deflector in the mxs listener. It is kind of incorrect, I just cheated. It could have easily have been Traffic[1] since there is only one deflector in the array and since there is only one particle. You would have to have another for loop that iterated through the deflector array to tell the state if there were more than one.

Simply for seeing the state of the deflector, whether it is up or down, just for debug. I find it easiest to see what is happening in a Script operator when you print out variables/states/values/ect. It is much like having the "Show Data" window open in Box#3.

Anton980
06-07-2011, 08:34 PM
Ah, so it's like a "print" command, except better. Thanks!

JohnnyRandom
06-07-2011, 09:12 PM
Exactly, with format you can insert as many variables into a string of text as you like. Also has options of tab/new line/ect. much better than print :)

CGTalk Moderation
06-07-2011, 09:12 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.