hi all,
i’m looking for a more efficient way to code the following:
i’m randomly spawning static particles across a large area, and want to assign them to different particle systems depending on their Vector3 position. they will be grouped together based on area, and there will be over 250 different areas.
i was going to use lots of if statements to decide what to do with each one, but there would be lots of them(250+, which is obviously not useable) . for example (pseudo code) for one location/area:
if (((vector3(x)>30)&&(vector3(x)<60))&&((vector3(y)>30)&&(vector3(y)<60))&&((vector3(z)>30)&&(vector3(z)<60)){
add to particle system
}
thats just testing if a particle is in one area - i want there to be over 250.
is there an efficient way to code this?
You can define all your area rectangles (ideally by script) and then for each particle system find a rectangle that contains it’s position. Then asign that particle system to correct area.
For areas you should have a collection (dictionary maybe) that maps area to rectangle, so knowing rectangle is enough to retrieve correct area
to make things easier for you i would use a “map” to avoid all the coding.
draw a picture in paint that represents your level. and use different colors to represent where your areas are.
drop your picture into a Texture2D variable. you can then line up your world X and Y position to the Texture2Ds X and Y to see what particle to use based on the corresponding colors. it would require a somewhat small amount of coding. if you are interested in this method let me know and i will post code to get you going.
Particles can have collisions turned on, which means they can interact with other physical objects (the grid) and generate callbacks. This might work, but not sure if it will be efficient with 250 grid zones.