1 Reply Latest reply on Jan 27, 2007 1:46 PM by kglad

    Help with boundaries

    jamiemac2005
      okay, so i have a box (40*40) which is acted upon by basic forces (gravity etc) and controlled by the left and right keys on the keyboard...

      and a static rectangle which is 450*50.. so i wrote a simple script to make the box stop moving in the y direction if the box is colliding with the rectangle...

      this all worked fine but when i add a rotation the box stops in thin air because the rectangle has a new width and height....

      okay so here's the part of the collision script i think i need to change

      var newY = this._y+ySpeed;
      var newX = this._x+xSpeed;
      var xBoxB1 = _root.line1_mc._x-(line1_mc._width/2);
      var xBoxB2 = _root.line1_mc._x+(line1_mc._width/2);
      var yBoxB1 = _root.line1_mc._y-(line1_mc._height/2);
      var yBoxB2 = _root.line1_mc._y+(line1_mc._height/2);
      if (newY+20>=yBoxB1 && newY-20<=yBoxB2 && newX+20>=xBoxB1 && newX-20<=xBoxB2) {
      ySpeed *= -0.4;
      jumpable = 1;
      } else {
      ySpeed += gravity;
      jumpable = 0;
      }

      here the script is on the box so "this" refers to the box and "_root.line1_mc" refers to the rectangle that has been rotated by 10 degrees... jumpable is a simple variable i stored to tell wether the box was on the ground(rectangle) or not... and every frame ySpeed is added to the box's _y position.... if this doesnt make sence then i'm sorry , i'm almost confusing myself.

      in the conditional statement i added 20 to the newY variable because thats half the box's height etc..

      so what i need to be able to do is find out where the rectangle is instead of the box around it??? if that makes any sence?

      cheers to anyone who can help me in any way... JAM