FORUMS: list search recent posts

# falling objects randomly

FAQ   •   VIEW ALL
 falling objects randomly on Sep 4, 2015 at 11:53:35 pm

Hello, i'm working on falling objects. The objects will be straight animated until time x.
At time x +-2sec.they should fall down via expression.

What i have on POSITION:

```seedRandom(0,true); sp=thisComp.layer("Control").effect("sp")("Slider"); amp = random(thisComp.layer("Control").effect("amp")("Slider")); gravity = random(thisComp.layer("Control").effect("gravityMin")("Slider"),thisComp.layer("Control").effect("gravityMax)("Slider")); TimeInPoint = random(thisComp.layer("Control").effect("TimeInPointMin")("Slider"),thisComp.layer("Control").effect("TimeInPointMax")("Slider")); if (time >TimeInPoint) { pos_x = Math.sin((time-TimeInPoint)*sp)*amp; pos_y= (time-TimeInPoint)*(time-TimeInPoint)*gravity; value + [pos_x,pos_y]; } else { position }```

What i have on ROTATION:

```seedRandom(0,true); sp = thisComp.layer("Control").effect("sp")("Slider"); amp = random(thisComp.layer("Control").effect("amp")("Slider")); TimeInPoint = random(thisComp.layer("Control").effect("TimeInPointMin")("Slider"),thisComp.layer("Control").effect("TimeInPointMax")("Slider")); if (time >TimeInPoint) { rotation_x = Math.sin((time-TimeInPoint)*sp)*(amp/2.6); value - rotation_x; } else { rotation_x=0 }```

The PROBLEM:

amp & TimeInPoint should be the same on both calculations.

What i've tried:

So i've tried to put the scripts in one document instead of two seperate:

```// GLOBAL VAR seedRandom(0,true); sp=thisComp.layer("Control").effect("sp")("Slider"); amp = random(thisComp.layer("Control").effect("amp")("Slider")); TimeInPoint = random(thisComp.layer("Control").effect("TimeInPointMin")("Slider"),thisComp.layer("Control").effect("TimeInPointMax")("Slider")); gravity = random(thisComp.layer("Control").effect("gravityMin")("Slider"),thisComp.layer("Control").effect("gravityMax")("Slider")); // POSITION + ROTATION if (time >TimeInPoint) { pos_x = Math.sin((time-TimeInPoint)*sp)*amp; pos_y = (time-TimeInPoint)*(time-TimeInPoint)*gravity; rotate_x = Math.sin((time-TimeInPoint)*sp)*(amp/2.6); thisComp.layer.rotation = value - rotate_x; thisComp.layer.position = value + [pos_x,pos_y]; } else { transform.position = value; rotate_x = 0; }; ```

BUT: It doesn't work.

The QUESTION:

How i get the same amp and TimeInPoint on both, rotation AND position?

THANKS FOR YOU HELP !!!!!

 Re: falling objects randomlyon Sep 5, 2015 at 3:12:05 am

You could put the calculations for amp and TimeInPoint on slider expressions and then reference those slider values from your position and rotation expressions.

Dan

 Re: falling objects randomlyon Sep 5, 2015 at 2:25:03 pmLast Edited By Conny Klar on Sep 5, 2015 at 4:38:02 pm

This is what i've done... Rotation and Position got the numbers from the same slider, but they take a different random. That's the reason why i've tried to put in one calculation in an external txt-file. But it doesn't work. It only takes either the rotation or the position...

Is there a way to grab the random-TimeInPoint from the position to use it in the rotation, because if rotation have another TimeInPoint than the position, the objects doesn't make the right turns...

 Re: falling objects randomlyon Sep 5, 2015 at 5:51:57 pm

I don't think you understood what I meant. You would put an expression like this on each of your sliders:

seedRandom(index,true);
random(value);

Then in your position and rotation expressions, the slider reference becomes like this:

amp = thisComp.layer("Control").effect("amp")("Slider");

and there is no mention of random in the position and rotation expressions themselves.

Dan

 Re: falling objects randomlyon Sep 5, 2015 at 6:29:40 pmLast Edited By Conny Klar on Sep 5, 2015 at 6:50:45 pm

Hey Dan, thanks for answer. As i can see i forgot the second value in the amp-random in the first post, ooops.
But I know what you mean... The slider aren't the problems... Let me breack it down without sliders, so the script can be better read:

in Position I have maybe:

```seedRandom(index,true); sp=2; amp = random(40,60); gravity = random(20,80); TimeInPoint = random(8,10); if (time >TimeInPoint) { pos_x = Math.sin((time-TimeInPoint)*sp)*amp; pos_y = (time-TimeInPoint)*(time-TimeInPoint)*gravity; value + [pos_x,pos_y]; transform.position = value + [pos_x,pos_y]; } else { position }```

in Rotation:

```seedRandom(index,true); sp=2; amp = random(40,60); TimeInPoint = random(8,10); if (time >TimeInPoint) { x = Math.sin((time-TimeInPoint)*sp)*(amp/2.6); value - x; } else { x=0 }```

Both, rotation and position should have the same amp and TimeInPoint. The amp something between 40 and 60 maybe and the TimeInPoint is something between 8 and 10 seconds. This works BUT: the position will grab an another TimeInPoint and amp as the rotation will do, but it is important that it goes together. Of course i can write it for every object without random, but we are talking about 500 objects. So i like to have it random, but every randomvalue needs to be the same per object (Layer). Do you know what i mean?

I need a "layerbinded" amp and TimeInPoint, so that every layer has a different amp and TimeInPoint, but each one the same in rotation and position.

 Re: falling objects randomlyon Sep 5, 2015 at 7:13:42 pmLast Edited By Dan Ebberts on Sep 5, 2015 at 7:17:03 pm

To get the same random value into both your position and rotation expressions, the random calculation has to be done externally to those expressions. That's why you set up your sliders to "publish" the random values, not the slider values. So the only use of random() should to be external to position and rotation, and should be done on the sliders themselves. That way, every reference to the sliders gets the same random values. If you have 500 objects, you'd probably want to set it up so that each object has its own set of random amp and time-in-point sliders.

I don't know how to explain it any better than that.

Dan

 You could set the individual (per-object) random sliders to reference a common slider to get the max value--that way you could adjust that value in one place.

 Re: falling objects randomlyon Sep 5, 2015 at 8:07:10 pm

So: i've made what you said. The calculation is in the sliders now. The numbers are synchron for rotation and position. Wohooo. But that means in the end, that i have to make 500 more Controls right ? :) Conny

 Re: falling objects randomlyon Sep 5, 2015 at 10:51:28 pm

If it were me, I would add the randomizing sliders to each object, either by adding them to one and duplicating that object 499 times, or by copying them from the first object and pasting them on to the other 499 objects.

Dan

 Re: falling objects randomlyon Sep 7, 2015 at 3:22:29 pm

Hey Dan, thanks for your help. That's not a good solution, because if i have to change the time, i have to change it in every object... Seems to be a job for a coder :)... Conny

 Re: falling objects randomlyon Sep 7, 2015 at 4:33:57 pm

No, you could have the randomizing expression of each local time slider pick up the min and max value from a central control layer:

random(thisComp.layer("Control").effect("TimeInPointMin")("Slider"),thisComp.layer("Control").effect("TimeInPointMax")("Slider"));

Dan

 Re: falling objects randomlyon Sep 7, 2015 at 5:04:51 pmLast Edited By Conny Klar on Sep 7, 2015 at 6:26:36 pm

Do you mean sth. like this? This could be a solution...

 Re: falling objects randomlyon Sep 7, 2015 at 7:05:06 pm

No, there would just be the Main control layer with the master slider values, and the object layers, each with its own randomizing sliders (which get their min/max values from the main control layer).

Dan

 Re: falling objects randomlyon Sep 8, 2015 at 4:47:33 pm

Thahahaha Dan sorry! Maybe i didn't understand. That's what i had. But than the numbers will be different in the different values like rotation and position.... And if i have an additional, slider which call's a random number, then the number is the same on every object. What i missunderstood? Sorry Dan, for stealing your time... Conny

 Re: falling objects randomlyon Sep 8, 2015 at 5:30:13 pm

I don't think so.

The main control layer with master sliders to control random ranges (no expressions on these).

Each object has its own sliders with expressions like this:

min = thisComp.layer("Control").effect("TimeInPointMin";
max = thisComp.layer("Control").effect("TimeInPointMax";
seedRandom(index,true);
random(min,max);

Object position and rotation property expressions reference these local sliders to get the same random numbers (which will be different for each object).

Dan

 Re: falling objects randomlyon Sep 8, 2015 at 6:55:43 pm

Whohoooooo Dan, TRIPLEFACEPALM... Now i understand! Sometimes i can't see the tree in the wood.

Now i have:

Control-Main-Layer with declaration of MIN and MAX

Object-Layer with sliders to grab one random-Number and the expression on rotation and position itself.

THAT WORKS !!!

Soooooooo, now i have (i hope so) my last question.

How i can talk with the layer itself without changing the layername?

Now i have in the expression of the layers positon and rotation:

randomTimeInPoint = thisComp.layer("layername").effect("randomTimeInPoint")("Slider");
randomAmp = thisComp.layer("layername").effect("randomAmp")("Slider");

That means for maybe about 500 objects to change the names per hand right? (What i'm missing again?):

thisComp.layer("layername")...
thisComp.layer("layername 1")...
thisComp.layer("layername 2")...

and so on...

As the objects aren't generated, the layernames are different.
Is there a way to call the layers with something like

thisComp.layer("this")... ?

Conny

 Re: falling objects randomlyon Sep 8, 2015 at 7:05:24 pm

Why not like this:

randomTimeInPoint = effect("randomTimeInPoint")("Slider");

Dan

 Re: falling objects randomlyon Sep 8, 2015 at 7:13:01 pm

OF COURSE, OF COURSE..... ( next Triplefacepalm :D )

You are the greatest !!!!

AMAZING !!!!!!!!!!!!!!!!!!!! IT'S WORKING !!! WOHOOOOOOOO...

(30sec dancing break)

Thanks for that, Dan !!!