6 Replies Latest reply on Nov 4, 2006 5:12 PM by kglad

    MC coordination

    mpwalker Level 1
      I'm building a simple adventure game engine using the Flash Virtual Camera. Basically, I need the camera MC to parallel the movement of the character MC so that he is always centered in the camera as he moves around and the camera stops moving in that direction when the character hits a wall. Here's the code on the character:

      //original code by edmack www.edmack.com
      onClipEvent(load){
      b = this.getBounds(this);
      s = 5;

      function move(x,y){
      if(!_parent.map.hitTest(_x+b.xMin+x, _y+b.yMin+y, true) &&
      !_parent.map.hitTest(_x+b.xMax+x-s, _y+b.yMin+y, true) &&
      !_parent.map.hitTest(_x+b.xMin+x, _y+b.yMax+y, true) &&
      !_parent.map.hitTest(_x+b.xMax+x-s, _y+b.yMax+y, true)
      ){
      _x += x;
      _y += y;
      }
      }
      }

      onClipEvent(enterFrame){
      if(Key.isDown(Key.UP)){
      move(0,-s);
      }
      else if(Key.isDown(Key.DOWN)){
      move(0,s);
      }
      if(Key.isDown(Key.LEFT)){
      move(-s,0);
      }
      else if(Key.isDown(Key.RIGHT)){
      move(s,0);
      }
      }


      I tried simply aligning the objects and saying on the camera MC:

      this._x = _root.hero._x;
      this._y = _root.hero._y;


      So simple it might work, I thought. Which it wort of did but was really glitchy and the character would end up getting stuck in walls and such. Very confused noob.

      Thanks for any feedback!