5/18/2010

Follow + Ease

A code snippet for a display object to follow a point or another object.

x -= (x - mouseX) / speed; y -= (y - mouseY) / speed;

6 comments:

  1. fairplay, thats pretty neat!

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Movement 2 result should be 4.44. But that doesn't really matter as it's still moving towards 3. Also in your example, you should keep xmouse constant as the object is moving towards it. Then it'll be easier to see how it works.
    The equation may be translated to:
    position change = distance difference / time

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Hi, I am trying to create a movieclip menu that follows the mouse but stops at a distance or when the mouse rolls over it. please what line of code do I insert in? thanks

    ReplyDelete