2 Replies Latest reply on Apr 16, 2007 1:50 AM by daveCph

    colission detection that goes wrong - WHY!!!! Arghhh!

    daveCph
      I have two mc's on the time line: car_mc and walls_mc and i have the following code in a frame:
      var distance:Number = 5;

      var keyListener:Object = new Object();
      keyListener.onKeyDown = function() {
      if (Key.isDown(Key.LEFT)) {
      car_mc._x = Math.max(car_mc._x - distance, 0);

      } else if (Key.isDown(Key.RIGHT)) {
      car_mc._x = Math.min(car_mc._x + distance, Stage.width - car_mc._width);

      } else if (Key.isDown(Key.UP)) {
      car_mc._y = Math.max(car_mc._y - distance, 0);

      } else if (Key.isDown(Key.DOWN)) {
      car_mc._y = Math.min(car_mc._y + distance, Stage.height - car_mc._height);

      }
      collide();
      };
      Key.addListener(keyListener);

      _global.collide = function(){
      trace("Im here");
      if(walls_mc.hitTest(car_mc._x , car_mc._y , true))
      {
      trace("boing")
      }
      }

      and this works - so far no problem.

      in the car_mc is a movie clip with instance name "tl" and I whish to detect collision between this and walls_mc but when I replace car_mc._x with car_mc.tl._x (and same with _y) it no longer traces "boing" when I expect it to. I tryed to ad "_level0." and "_root." as well to both walls_mc and car_mc (which is the result I get when I "trace(this)" on the objects).

      I gather that my referencing is faulty but not how and why. Please help

      DaveCph