Jump to content
Search Community

Question: Adobe Animate - Random Movement

witochka 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

Greetings guys,

 

I'm fairly new to GreenSock and Coding, like everyone who is just getting started, I quickly arrived at a point where I don't know how to continue:

 

I'm working in Adobe Animate and I wanted my movieclip hexagon (InstName = hexagon) to move randomly on my canvas. 

As an end goal, I wanted several hexagons to move around randomlymaybe even change in size, and I wanted it to play infinitely (screenshots attached).

 

I found an old tutorial with some code and tried to apply it, but it didn't work. Can anyone tell me why? Is it because I'm using jQuery?

 

Scripts included:

https://cdnjs.cloudflare.com/ajax/libs/gsap/1.20.3/TweenMax.min.js

http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.js

 

Code:

 

var randX;
var randY;

function randomNumbers(){
    
    randX = Math.floor(Math.random()*100);
    randY = Math.floor(Math.random()*150);
    moveMe();
}

randomNumbers();

function moveMe(){
    sym.$("hexagon").animate({left: randX, top: randY},1000, randomNumbers);
}

 

 

How can I achieve my goal? Or can anyone please send me a link where a similar topic is solved and discussed?

 

Any help would be greatly appreciated!

Bildschirmfoto 2018-01-24 um 10.30.25.png

Bildschirmfoto 2018-01-24 um 10.30.47.png

Link to comment
Share on other sites

Hi and welcome to the GreenSock forums,

 

jQuery isn't going to work inside Animate CC. jQuery is for working with DOM elements (div, span, img, etc) and Animate is all canvas using the EaselJS library for rendering.

 

The simplest way for constant random motion is to create a function that creates a tween that moves something randomly. When that tween is finished you call the same function again and tell it to move the same thing again to other random coordinates.

 

The code for 2 objects to move randomly and independently looks like this:

function moveIt(it) {
 TweenLite.to(it, (Math.random() * 2) + 0.5, {x:Math.random() * 400, y:Math.random() * 400, onComplete:moveIt, onCompleteParams:[it]});    
}
    
moveIt(this.box);
moveIt(this.box2);

 

 

demo: https://greensock.com/forums-support-files/randomMovement/randomMovement.html

 

I have attached a zip of the files.

 

 

randomMovement.zip

  • Like 3
Link to comment
Share on other sites

  • 2 years later...
1 hour ago, popedaddy69 said:

I've pasted the script into actions but I can't run it and it says "Scene 1, Layer 'Layer_11', Frame 1, Line 2, Column 2    1120: Access of undefined property TweenLite." How do I fix this?

Sounds like you just forgot to load GSAP :)

 

If you need some help with installation, see https://greensock.com/install

  • Like 1
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...