Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions How get a random position with fixed numbers

  • How get a random position with fixed numbers

    Posted by Levris Levr on October 12, 2017 at 10:55 pm

    I heave a fixed positions for X – simple [1, 4, 6, 9, 45, etc] and fixed posotions for Y [3, 8, 56, 32, etc]
    What expressions i need to use to set my object in random X position of [1, 4, 6, 9, 45, etc] and Y of [3, 8, 56, 32, etc] in every frame ?

    Levris Levr replied 8 years, 10 months ago 2 Members · 2 Replies
  • 2 Replies
  • Andrei Popa

    October 13, 2017 at 7:35 am

    I don’t know how you save your variables. I will asume that you declare them inside your expression. This first expression if for using same position of x and y(third x matches third y)
    xArray = [100,300,500,700];
    yArray = [200,400,600,800];
    randomPosition = Math.round(random()*(xArray.length-1));
    x = xArray[randomPosition];
    y = yArray[randomPosition];
    [x,y]

    This code is for using random x and random y.

    xArray = [100,300,500,700];
    yArray = [200,400,600,800];
    xrandomPosition = Math.round(random()*(xArray.length-1));
    yrandomPosition = Math.round(random()*(xArray.length-1));
    Math.floor(random()*xArray.length);
    x = xArray[xrandomPosition];
    y = yArray[yrandomPosition];
    [x,y]

    Feel free to ask if you need any further explanation.

    Andrei

  • Levris Levr

    October 13, 2017 at 11:54 am

    Thanks !!!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy