A Flash Developer Resource Site

Results 1 to 1 of 1

Thread: random movement around non uniform shape

  1. #1
    Senior Member
    Join Date
    Aug 2006
    Posts
    293

    random movement around non uniform shape

    hi all,

    i'm hoping that someone can help me out here.

    attached is an .fla file that has a number of movieclips that move around at random, this part works great. but the movement is only applicable to a rectangle/uniformed area - defined in the action script on frame 1.

    PHP Code:
    function getdistance (xyx1y1) {
        var 
    runrise;
        
    run x1-x;
        
    rise y1-y;
        return (
    hyp(runrise));
    }
    function 
    hyp (ab) {
        return (
    Math.sqrt(a*a+b*b));
    }
    MovieClip.prototype.reset = function () { 
    var 
    distnormmovie_heightmovie_width;


    //   movie_height: refers to the height of your movie
    //   movie_width: refers to the width of your movie

    //--------------------------------------------

    movie_height 150;
    movie_width 300;

    //--------------------------------------------


    speed Math.random()*4+2;
    targx Math.random()*(movie_width-_width);
    targy Math.random()*(movie_height-_height);
    dist _root.getdistance(_x_ytargxtargy);

    norm speed/dist;
    diffx = (targx-_x)*norm;
    diffy = (targy-_y)*norm;
    };


    MovieClip.prototype.move = function () { 
    var 
    cycle;



    // cycle: specifies speed of the movement. The smaller 
    //         number, the faster the objects move.

    //--------------------------------------------

    cycle 200;

    //--------------------------------------------

    if (_root.getdistance(_x_ytargxtargy)>speed) {+= diffx;+= diffy;
    } else {
    targx;
    targy;
    if (!
    this.t) {
    getTimer();
    }if (
    getTimer()-t>cycle) {reset();
    0;
    }
    }
    _x x;
    _y y;

    and each clip that moves randomly has this script applied...

    PHP Code:
    onClipEvent (enterFrame) {
        
    move();

    what i want the clips to do is move around within the area of the big mc named "area" in the middle of the stage - by which i mean move anywhere within the boundaries of the shape of the "area" but never outside.

    i remember i did something similar many many moons ago - but can't find any reference/files/scripting for what it was that i did to make it work. not sure if the phrase "shape flag" is something that is on the right lines? it was so long ago!

    does anyone know what i need to add/edit/change in the AS shown above to achieve the desired effect please?

    be really grateful for any pointer, tips or help that anyone feels generous to offer me

    fingers crossed...
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center