0 Replies Latest reply on Jul 17, 2006 12:26 PM by chieffan

    hittest within random movement help needed

    chieffan
      I have everything setup fairly well I believe (thanks to Kirupa). I have a large circle movie clip in the center of my stage and four movie clip cirlces outside of it. I don't want the four circles to get inside the large circle and am in need of assitance with my hittest as I am not 100% sure where to put it and if I need to rewrite some code.

      This code is on the circle movie clip where ai1 is the small circle and circleField_mc is the large circle. It kind of works but what happens is the small circle eventually gets inside the big cirlce kind of by default.

      onClipEvent (enterFrame) {
      if ((_root.ai1.hitTest(_root.circleField_mc))) {
      trace("hit circle");
      reset();
      move();
      } else {
      move();
      }
      }

      On frame 1 of my movie I have this code which increases/decreases the small circles sizes and finishes the random movement.

      scale = 100;
      counter = 3;
      ai = new Array(ai1, ai2, ai3, ai4);
      removeControl_mc.onRelease = function() {
      if ((scale>=25) && (scale<=99)) {
      scale = scale+25;
      for (i=0; i<ai.length; i++) {
      ai ._xscale = scale;
      ai
      ._yscale = scale;
      }
      }
      };
      addControl_mc.onRelease = function() {
      if ((scale>=26) && (scale<=100)) {
      scale = scale-25;
      for (i=0; i<ai.length; i++) {
      ai ._xscale = scale;
      ai
      ._yscale = scale;
      }
      }
      };
      //special thanks to Suprabeener for the code
      function getdistance(x, y, x1, y1) {
      var run, rise;
      run = x1-x;
      rise = y1-y;
      return (_root.hyp(run, rise));
      }
      function hyp(a, b) {
      return (Math.sqrt(a*a+b*b));
      }
      MovieClip.prototype.reset = function() {
      //specify the width and height of the movie
      width = 390;
      height = 240;
      //-------------------
      var dist, norm;
      this.x = this._x;
      this.y = this._y;
      this.speed = Math.random()*4+2;
      this.targx = Math.random()*width;
      this.targy = Math.random()*height;
      dist = _root.getdistance(this.x, this.y, this.targx, this.targy);
      norm = this.speed/dist;
      this.diffx = (this.targx-this.x)*norm;
      this.diffy = (this.targy-this.y)*norm;
      };
      MovieClip.prototype.move = function() {
      if (_root.getdistance(this.x, this.y, this.targx, this.targy)>this.speed) {
      this.x += this.diffx;
      this.y += this.diffy;
      } else {
      this.x = this.targx;
      this.y = this.targy;
      if (!this.t) {
      this.t = getTimer();
      }
      if (getTimer()-this.t>10) {
      this.reset();
      this.t = 0;
      }
      }
      this._x = this.x;
      this._y = this.y;
      };

      Thank you.