MAXScript Extensions > MAXScript Extensions for Particle Flow > Particle Flow Script Examples > Particle Channel Scripts >

# particleVector Sample Script

| Particle Flow - Quick Navigation

Description:

The following sample script assigns Vector values to the particleVector channel.

Can Be Used With:

Can be used in a Script_Operator to control the Target Point position of a Find_Target Test.

Effect:

Takes a scene geometry object, gets the position of its first vertex, adds a random offset to it and assigns to the particleVector channel of all particles. In result, all particles stream towards the vertex thanks to the Find_Target which is set to read the particleVector channel and send all particles to the position in the channel:

EXAMPLE
    --The ChannelsUsed handler defines the channels
    --to be made available to the script.
    --For the list of all channels, see
    --Interface: MaxscriptParticleContainer
    --The parameter pCont passed to the handler
    --contains the Particle Container the script is applied to
    on ChannelsUsed pCont do
    (
    --Enable the Vector channel:
    pCont.useVector = true
    )

    --The Init handler is called on initialization.
    --It is not used in this case.
    on Init pCont do
    (
    --Define a global variable with unique name and store the
    --scene object which also has a unique name in it
    global obj_19680217 = $Sphere_19680217
    --If the scene object does not exist, create a sphere,
    --give it the unique name and assign to the global variable
    if obj_19680217 == undefined then
    obj_19680217 = Sphere name:"Sphere_19680217"
    )

    --The Proceed handler contains the main script
    --applied to the Particles.
    --The parameter pCont passed to the handler
    --contains the Particle Container the script is applied to:
    on Proceed pCont do
    (
    --Get the current number of particles
    count = pCont.NumParticles()

    --Loop from 1 to the number of particles:
    for i in 1 to count do
    (

    --Set the particle index in the container to the current i value.
    --This makes the i-th particle in the container the current one
    pCont.particleIndex = i

    --Get the position of the first vertex of the scene object.
    vpos = (getVert obj_19680217.mesh 1)

    --Add a random variation between -1 and +1 to all 3 axes
    vpos += random [-1,-1,-1] [1,1,1]

    --Set the particleVector channel value to the calculated value
    pCont.particleVector = vpos
     )--end i loop
    )--end Proceed

    --The Release handler is used to do cleanup work.
    --Not used in this case.
    on Release pCont do
    (
    )

#### See Also

- Interface: MaxscriptParticleContainer

- Script_Operator : Helper

- Find_Target : Helper

- Using MAXScript in Script Actions

- Particle Flow Sample Scripts