Jump to content
Search Community

Randomizing doesn't change in recursion

drewbit test
Moderator Tag

Warning: Please note

This thread was started before GSAP 3 was released. Some information, especially the syntax, may be out of date for GSAP 3. Please see the GSAP 3 migration guide and release notes for more information about how to update the code to GSAP 3's syntax. 

Recommended Posts

I'm trying to randomize some settings in a tween. The first time it gets random values, but each iteration thereafter is identical.

 

function RandomTween(e,o,w,h){
     TweenMax.to(e, 0, {x:(int(o.left*w)), y:(int(o.top*h)),rotation:getRandomArbitary(1.05,6.25)+"rad"});
     TweenMax.to(e, getRandomArbitary(0.5,5), {y: o.animation.to.y*h,repeat:-1,x: o.animation.to.x*w,force3D:true,
rotation:getRandomArbitary(1.05,6.25)+"rad",ease:Linear.easeNone,onComplete:function(e,o,w,h){
RandomTween(e,o,w,h);
        },onCompleteParams:[e,o,w,h]});
}
/**
 * Returns a random number between min and max
 */
function getRandomArbitary (min, max) {
    return random() * (max - min) + min;
}
var seed = 1;
function random() {
    var x = Math.sin(seed++) * 10000;
    return x - Math.floor(x);
}

 

Am I missing something here?

Link to comment
Share on other sites

It appears you are only getting random values once as your onComplete callback is applied to a tween with repeat:-1 which means the tween will repeat indefinitely and never complete.

 

From what I gather, you don't need your tween to repeat at all as each time it completes it should call that function again and generate a new tween.

 

Also it seems you are creating 2 tweens on the same target that both change the y value. Currently the second tween will kill the y part of the first tween.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...