6 Replies Latest reply on Nov 25, 2007 2:25 PM by *sanchez**

    mouse distance controlling MC

      ive got this code so a MC will follow the cursor on the x axis

      this.dog.onMouseMove = function() {
      if (_root._xmouse<600 && _root._xmouse>0) {
      this._x = _root._xmouse;

      but i also want the MC to do different things depending on the distance of the mouse from the MC

      something like... if mouse within 100px MC.gotoandplay(jump) if mouse more than 100px and less than 400px MC.gotoandplay(stand) if mouse more than 4 MC.gotoandplay(laydown)

      and also if MC is sliding to follow mouse i want the MC to gotoandplay(walk)

      heres diagram to help explain
        • 1. Re: mouse distance controlling MC
          *sanchez** Level 1
          try not to laugh buts heres a animation showing what i want lol

          • 2. Re: mouse distance controlling MC
            Level 7
            *sanchez** wrote:
            > try not to laugh buts heres a animation showing what i want lol
            > http://www.bencraig.com/misc/example.swf

            You did not ask a question.

            I wouldn't put the code on an mousemove handler otherwise you dog only
            moves while the mouseposition has changed. But you want the dog to
            follow the mouse more slowly otherwise it will have allways the same
            position as the mouse.

            Put it on an enterFrame handler.

            Check if the mouse is more left or more right of the dog and increase or
            decrease the dog's position. Use 'else' conditions. Check if the dog has
            the right x and y position to the mouse and then trigger your animation.
            And what happens if I move the mouse then? If the cursor should stay
            there use hide cursor and use a movieclip as cursor that is set to the
            position of the mouse.
            • 3. Re: mouse distance controlling MC
              *sanchez** Level 1
              yea sorry forgot the question lol
              i was hoping for someone to show me some code cos i really cant figure it out
              • 5. Re: mouse distance controlling MC
                clbeech Level 3
                Hey sanchez, what you're looking for here is fairly complex. Marco is on the right track, but there's another complication, not only does the dog need to run the walk cycle, but he must walk with each step toward where the mouse currently is and then stop. If you were to simply adjust the _x position of the dog, he will just magically 'snap' to the position of the cursor, so he has to walk though his step sequence until he reaches the mouse point, ya see what I mean?

                So beyond setting things up in an onEnterFrame event, you must move the dog slowly through his walk cycle, with each step checking to see if he's reached the mouse position. then run other checks (ie. the vertical ones) to perform a different actions. I have constructed a very simple animation (don't laugh Georgense :) of what you're looking for here, but just the walk cycle, you'll need to work out the jump and sit cycles and add to the basic code construction I'm giving you as an example.

                what this does is, at the beginning of the dogs MC, checks for the mouse position, adjusts the needed variables, and sends the playhead to the walk cycle, the walk cycle adjust the position of the clip as it walks, then sends the playhead back to the first frame at the end of the cycle. By doing so, this envokes the method once again and it checks to see if he's reached the current position of the mouse, and if not repeats the walk cycle, and so on. Additionally, there is a onMouseMove event trigger on board with a boolean to control the timing, so that when he's reached the position of the mouse and is just standing there, if the mouse is moved, he begins the sequence once again.

                All of the code is within the dog MC, double click to take a look. remember this is a very simple example and the cycle is rough. Also you will need to add to the conditions in the checkPosition method for the verticle mouse position, and then develop the sequences for them, as well as adding methods to handle the change.

                Here the FILES
                • 6. Re: mouse distance controlling MC
                  *sanchez** Level 1
                  thats awesome thanks! :)

                  i also got this code... ill be back when i have a finised movie. cos i know ther a alot of people around in lots of forum trying to find something like this