A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: math formula

Hybrid View

  1. #1
    Senior Member
    Join Date
    Mar 2001
    I got this code from a friend that makes objects move away from your mouse like a backwards magnet, then moves back into place after the mouse is gone. I want to upgrade the code to scale the object down the further away it moves out of place, then return to full size when it moves back into place. I've tried a few diffrent things, nothing worked, I am pritty much confused how to do it at this point. If anybody could help me I would really appreciate it. Thanks in advance.

    //variables loaded once
    homeX = this._x
    homeY = this._y
    magnet = 500

    //variables = sub formula that update every new frame
    x0 = this._x
    y0 = this._y
    x1 = _root._xmouse
    y1 = _root._ymouse
    distancex = x1-x0
    distancey = y1-y0
    distance = Math.sqrt((distancex * distancex) + (distancey * distancey))
    powerx = this._x - (distancex / distance) * magnet / distance
    powery = this._y - (distancey / distance) * magnet / distance
    forcex = (forcex + (homex - x0) / 2) / 1.66
    forcey = (forcey + (homey - y0) / 2) / 1.66

    this._x = powerx + forcex
    this._y = powery + forcey

    This is a link to see what the code is doing now.

    Thanks again for any help.

  2. #2
    try this:

    add this to the onload event



    at the end of the script add:



    anyvariable is a number that will be more than the heighest distance possible from the mouse. eg. if your movie is 500x400, choose something like 500. Anyway, play around with the number and choose the best one for you.

    this way the smallest size it can get to is 0.5 of its original. You can make it smaller by making the 0.5 0.7 etc...

    hope that helps.

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