Notifications
Clear all

[Closed] object pos = particle pos problem

i understand completely how busy you must be. thanks a bunch for all your help!

is any1 else on the forum able to help me out with this task?

Hi.

I think this should work.

on Proceed pCont do 
(
	-- Array of objects
	global points = $Point* as Array

	-- Particle count
	count = pCont.numParticles()
	-- Integration step for our particle flow node
	integrationStep = $PF_Source_01.getIntegrationStep()
	-- Speed multiplier
	speedMult = integrationStep.ticks
	
	-- Reset objects position
	if currentTime >= 0 then points.pos = [0,0,0]

	-- Loop through each particle
	for i = 1 to count do (
		-- Set current particle
		pCont.particleIndex = i
		-- Calculate the current object location based on the particle position
		points[i].pos = pCont.particlePosition + pCont.particleSpeed * speedMult
	)
)

Hope it helps.

that works perfectly! Many many thanks to you HalfVector! Now if its not too much trouble, would you mind explaining the math and/or reasons behind this code so that i may further my understanding of maxscript ? Most of it is straight forward, its just the integration step part that i’m not sure of. If its too complex, i understand, but it would be the icing on the cake if its not too much trouble!

Well, I’m not sure about this but anyway…

Ok, seems like the position (particlePosition) of the particle in the Proceed method is not the position for the current step but for the previous one, that is, the actual position is not calculated yet (that’s the part I’m not sure of!).

So you have to calculate the actual position yourself.

If the physics would be calculated once per-frame, it would be as simple as:

objectPos = pCont.particlePos + pCont.particleSpeed

But keep in mind that PFlow can calculate the “physics” of the particle system more than once per-frame. The number of times it is calculated comes defined by the integration step property. So if the integration step is 1/8 frames, the “physics” will be calculated eight times per frame (once each 0.125 frames or 0.125 * 160 = 20 ticks).

That means that if you have to calculate the position for the next step, you can’t just add the speed as we did before. We have to scale the speed depending on the integration step. That’s why I get the integration step with the function getIntegrationStep() (returns the integration step in viewport mode if MAX it’s no rendering or in render mode otherwise), convert that to ticks and finally, when calculating the actual position, I add the scaled speed.

objectPos = pCont.particlePosition + pCont.particleSpeed * scaledSpeed

Sorry if I’ve not been clear enough but my english is somewhat terrible!.

Good work fella

thanks again to both of you for the help on this one. I’m only just getting into maxscript now. I mainly want to use it for particle flow.

Does anyone know of any good pflow specific scripting tutorials or dvds even ? I know the cg-academy ones are good but they’re not really centered around pflow.

Page 2 / 2