Curve randomize attribute

I have created curves as attributes but they are missing the ‘Randomize’ button seen in the Particle System component. How can I enable this feature in my own curve attribute?
On a side note, any idea how I would find the source code for the Particle System component and others? I know PlayCanvas is open source, but I don’t feel like trodding through the entire folder structure just to find 1 file if there is an easier method.

Hmm. Not sure if that is exposed to script attributes annoyingly (this would be a nice feature so please ask for it on the engine repo). The way it comes through to the particle system is as two curve graphs and if the second one is not null, it randomises between the two.

You can replicate this somewhat with a curveset so you can plot two curves on the same graph.

Then the value can be evaluated by and you would have to do a random call between the two values received.

Easiest way is to ‘go to file’ on GitHub repo:

And search for ‘particle’.

Or, go to the component folder:

And look for the component.js file in the component you are looking for.

1 Like

As an example, it looks something like this:

var RandomCurve = pc.createScript('randomCurve');
RandomCurve.attributes.add('randomCurve', { type: 'curve', curves: [ 'min', 'max'] });

// initialize code called once per entity
RandomCurve.prototype.initialize = function() {
    this._tempPoint = [0, 0];
    this.randomCurve.value(0.3, this._tempPoint);
    console.log(pc.math.random(this._tempPoint[0], this._tempPoint[1]));

1 Like