Participant
March 14, 2024
Question
Expression help// occasional random movement in one of four directions
- March 14, 2024
- 1 reply
- 511 views
Hey All!
I'm trying to create an expression that will randomly move a square one of four ways, and only do so occasionally. I've got it close, and I think it's working except for - the square returns to its home anchor point every time. The idea is that it would move North, East, South, or West about 30% of the time, and the rest of the time it would just stay in its last position. I am sooooo close with this script:
segDur = .5;// duration of each "segment" of random motion
seed = Math.floor(time/segDur);
segStart = seed*segDur;
amt=800;
south=[0,-1*amt];
north=[0,amt];
east=[amt,0];
west=[-amt,0];
seedRandom(seed,true);
m=Math.round(random(1,15));
if (m==1){startVal=north}
else if (m==2){startVal=south}
else if (m==3){startVal=east}
else if (m==4){startVal=west}
else startVal=[0,0];
seedRandom(seed+1,true);
m=Math.round(random(1,15));
if (m==1){endVal=startVal+north}
else if (m==2){endVal=startVal+south}
else if (m==3){endVal=startVal+east}
else if (m==4){endVal=startVal+west}
else endVal=[0,0];
ease(time,segStart,segStart + segDur, startVal, endVal)Obviously stole a lot of this from @Dan Ebberts and have been modifying on my own for two days. I just KNOW that as soon as someone points out the solution I will be incredibly frustated with the simplicity of the code. But i've spent too much time on it and client needs it done. Can anyone point out how stupid I have been?
