x


Shuriken, change Random Between Two Constants by script

For several parameters, Shuriken is giving different ways to affect it in the editor : constant, curve, random, gradient etc. However, by script you can only affect a constant value, like for instance :

system.startSize = 5f; // Can't specify a curve or a range, it's a float !

Is there some secret ninjas ways to do that, or do I need to do every frames :

// Or curve.Evaluate(system.time/system.duration)
system.startSize = Random.Range(min, max); 

As we are talking, among other things, about Shuriken's random stuff, here is an interesting paper (unrelated to the issue here, and yet kind of, as the result above won't be similar to the builtin one, because the random value is re-sampled, thus not connected).

----------
[Edit] Apparently, when a float parameter is set "Random Between Two Constants", affecting a new value will set it as the second constant, and the first will then be firstValue * (lastSecondValue / newSecondValue). For instance, you set startSize in the inspector between 1 and 3. Then in Awake, you do startSize = 5; startSize is now between 1.66 and 5. It's empirical, so take it carefully. I didn't found any ways to set both values, or curves, gradient, two curves or two gradients.

more ▼

asked Mar 04 '12 at 04:07 AM

Berenger gravatar image

Berenger
11k 12 19 53

Bringing that question up, trying my luck ...

Mar 08 '12 at 04:43 PM Berenger

Last time, I promess !

Mar 16 '12 at 04:56 PM Berenger

I've found the script interface leaves some room for improvement - for example, interpolating a particle system between two states seems difficult. Sorry I can't help you, but want to note that I also struggle with this.

Mar 21 '12 at 06:24 PM kromenak

I hope they are going to improve it in further versions, that's probably only the first step.

Mar 23 '12 at 03:40 PM Berenger

Any news for this ? (up)

May 03 '12 at 04:56 PM Berenger
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Shuriken is a curiously dark box when looked at from a scripting perspective -- there are many parameters you can manipulate in the editor that are not accessible from script, even things as simple as the size of the emitter.

The best Secret Ninja Sauce(TM) I've found is to use the editor to create an animation that animates a particle system property from a minimum value at the start of the animation to a maximum value at the end of the animation, then from your script you can update the animation state using normalizedTime to select a value between min and max (0 for min, 1 for max).

You can get the animation state like this (probably best to do this in Awake or Start) ...

AnimationState setScaleAnim = animation["setScale"];

And then set your value to (say) halfway between min and max with ...

setScaleAnim.normalizedTime = 0.5f;

You can set up a bunch of animation states, one for each parameter (or set of parameters) that you want to procedurally control.

It's a little indirect, but it does give you scripted control of anything you can see in the Shuriken editor.

more ▼

answered Jun 23 '12 at 06:11 AM

yoyo gravatar image

yoyo
6.4k 25 39 84

Yup, that does sound like a good way around. Thanks :)

Jun 23 '12 at 03:07 PM Berenger

I haven't tried it, but for bonus points it should even be possible to create and add AnimationClips procedurally, for full control.

Jun 24 '12 at 03:18 AM yoyo
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x644
x575
x165
x86

asked: Mar 04 '12 at 04:07 AM

Seen: 1633 times

Last Updated: Jun 24 '12 at 03:18 AM