Random FX, not very random.

edited October 2011 in Help request
I thought I'd asked something like this previously, but I can't seem to find it...

I've got the equivalent of snowflakes falling: a large set of objects with a downward velocity. I was hoping to use FX to simulate a gentle, random, back-and-forth horizontal motion.
SlotList = SnowflakeWobble

Type = position
Curve = sine
StartTime = 0
EndTime = 0.75 ~ 1.0
StartValue = (0, 0, 0)
EndValue = (-100, 0, 0) ~ (100, 0, 0)

The values would be tweaked with, but you get the idea. I use orxObject_AddFX() to give this effect to each one of my objects; however, even though I specify random ranges for several values, all of my snowflakes fall in exactly the same pattern! I know the Wiki mentions that the random values are only calculated whenever the config file is actually read, so I'm assuming this only happens once and is then applied to all snowflakes.

Is there a "best practices" way around this, so that each snowflake is given completely random motion?


  • edited October 2011
    Mmh, I remember answering a similar question but I think it was faistoiplaisir who asked it to me in private a few months ago.

    So I see two simple solutions depending on the result you want:
    - you could actually define a given number of options like fast, medium and slow, for example, and put them in different FXs. Then you can pick randomly one of those FXs when you apply them (if you store their name in a config list, by using this indirection, the random selection will be done for you by orx). That's the approach I use in my bounce playground for the particles spawned from the cursor.
    - you can duplicate this FX under different name and still keeping the random range inside. Instead of doing so in config manually, I'd do it at runtime. Let's say you have less than 1000 flakes simultaneously alive. Than means that having 1000 FXs would give you an unique random everytime as when you come back to the first one it won't be in memory anymore and thus its random will get reevaluated. So that's how it works: keep a counter somewhere in memory. At loadtime you create a section whose name contains the counter for each value (MyFX0, MyFX1, ...) and everytime you create such section you then set its parent to the real FX definition and keep the section itself empty. You now have 1000 random FXs that can be played simultaneously! When you need to apply one, simply recreate its name based on the current value of your counter then increase/modulo the counter.

    A last, less easy, option would be to add FXs not from config but programmatically, but that means you'd be responsible for creating them and then deleting them. I'm too lazy to do that myself. ;)
Sign In or Register to comment.