- Home /
Get Height of Particle System
Morning,
I'm making an obstacle system. I have a float inactive height and a float active height for the resting / active height the obstacle will move to during animation. This works for every obstacle except the ones involving a particle system, as there's no actual height field for the particle system.
How can you calculate the height (in world space) of the particle system?
Answer by wibble82 · Feb 11, 2014 at 02:01 PM
You can get all the particles in the particle system using particlesystem.GetParticles. This gives you an array of Particle objects, each of which has a position.
If you get the list of particles, run over each of their positions and calculate the highest and lowest y coordinate, then the height is highest-lowest.
Is that what you're after?
Thanks for the suggestion, but I'm more after setting a height than getting a height. $$anonymous$$now any ways I could do something like ParticleSystem.Height = x ?
What would what setting a particle system's height do exactly? Its ultimately just a point in space that emits particles so doesn't have a height as such. At any given time you can work out the bounding volume of the particles its emitted, but there's no height to 'set' exactly. $$anonymous$$aybe explain what you want this height value to do?
I'm making a platformer.
I have randomly generated obstacles that include obstacles that require particle systems (like a flame trap)with semi-random parameters including height, frequency that it'll go off, and damage that it'll do when it goes off.
I don't want all of the flame traps to be going off at the same height, so I need to adjust the height in some way ins$$anonymous$$d of pre-setting the specific level instance. For example, when the level is loaded one time I want
Trap 1 - height of 10
Trap 2 - height of 20
Trap 3 - height of 5
Trap 4 - height of 10
Then when I reload the level a second time, I want it to be something like
Trap 1 - height of 20
Trap 2- height of 5
Trap 3 - height of 40
Trap 4 - height of 30
I hope I clarified its' purpose enough.
I see. Well the particle system is really just a visual effect on the 'fire ball' that gets shot upwards. Personally I'd do this with 2 game objects:
a fire trap object, with a script on that every now and then generates a fire ball object (with its own script)
the fire ball object has a script attached that causes it to die after a period of time, and also has 1 or more particle emitters on that leave a trail of burning fire behind you!
That way, you can use the physics to detect when the fire ball hits the player and use it to deal them damage. Ultimately though the key is that the particle system is just a visual that is attached to the fire ball.
Does that make a bit more sense?
Yes, what you're saying makes sense.
I guess I got a little bit too over-zealous when I found out about OnParticleCollision(GO c). It has the exact effect that I want without the height aspect which makes it hard to manipulate in my specific scenario.
As far as your suggestion -- that actually sounds like one of my other traps (aside from the trail of fire, which could be cool. Trail of flying javelins might be a little weird, though) but I'm going to change this trap from a stationary flame that starts and stops to maybe an elevated object that rises and recedes.
Thanks for all your help. I do appreciate it! I'm going to screw around with it a little bit when I get home and see if I can somehow get the effect but I want but I'm assu$$anonymous$$g I can't. In that case, I'll do the previously mentioned thing of changing up the traps.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Renderer on object disabled after level reload 1 Answer
Extinguish fire with water particle system 0 Answers
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer