A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: follow the cursor... but not all the way!

  1. #1
    damn, im smooth drkknght's Avatar
    Join Date
    Feb 2001
    Posts
    159

    follow the cursor... but not all the way!

    im trying to create an animation that features a movie clip following the mouse cursor. the further the cursor is, the faster the movie clip moves towards it.

    however, i do NOT want the MC to go all the way to the cursor.

    rather, id like to have it contained within a specific area (meaning it can only travel so far towards the mouse cursor, before it is completely halted).

    the current code i have (which does not stop the MC at a point, like i'd like it to) is as follows:

    Code:
    onClipEvent (enterFrame) {
    //x movement
     mx=_root._xmouse;
     if (mx<_x) {
     dx=_x-mx;
     }
     else {
     dx=mx-_x;
     }
     moveSpeedx=dx/10;
     if (mx<_x) {
     _x=_x-moveSpeedx;
     }
     else {
     _x=_x+moveSpeedx;
     }
    //y movement
     my=_root._ymouse;
     if (my<_y) {
     dy=_y-my;
     }
     else {
     dy=my-_y;
     }
     moveSpeedy=dy/10;
     if (my<_y) {
     _y=_y-moveSpeedy;
     }
     else {
     _y=_y+moveSpeedy;
     }
    }
    i have the action applied to the MC.

    how can i alter it to get the MC to stop at a certain point?

    thanks,
    i'm not new to action scripting. i'm just bad at it.

  2. #2
    Senior Member tigersbite's Avatar
    Join Date
    Apr 2002
    Posts
    314
    This might help steer you in the right direction
    Attached Files Attached Files

  3. #3
    damn, im smooth drkknght's Avatar
    Join Date
    Feb 2001
    Posts
    159
    heya tiger -- thanks for the response!

    definitely gettin closer here

    instead of a "deadzone" area, tho (where the following object is always X amount of pixels from the mouse) ...

    im looking moreso for a containment area -- so that no matter where the mouse is moving to (or how far its moving away) the movie clip following the cursor always stays in its little, invisible "cage".

    additionally, the MC has to still be responsive to the cursor. for example: the MC will still move up if the mouse does, even tho it cant move to the right anymore

    that make sense?
    i'm not new to action scripting. i'm just bad at it.

  4. #4
    Senior Member tigersbite's Avatar
    Join Date
    Apr 2002
    Posts
    314
    See if this one works fer ya.
    Attached Files Attached Files

  5. #5
    damn, im smooth drkknght's Avatar
    Join Date
    Feb 2001
    Posts
    159
    wuhoo!!

    thats more like it!

    this is almost perfect -- a TREMENDOUS starting point (now i just gotta customize the stuff).

    excellent job, tiger -- thanks so much for the assistance!

    (im currently testing different "container" shapes, like diamonds and such. very fun!)
    i'm not new to action scripting. i'm just bad at it.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center