A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: MATH in Actionscripting (creating motion?)

  1. #1
    I am really interested in trying to use mathematics to create motion in my flash movies i have looked to open fla's or tutorials on the subject but don't really find much. Does anyone know where i might find out how to implement the linear equations used to create a line between one point and another base on the location of both points and the distance in between. I feel pretty comfortable with looping and getting and setting properties i just need help with the proper equations. Any help would be appreciated. Thank you.

  2. #2
    If you have two coordinate pairs, (x1,y1) and (x2,y2), then the slope of the line between them is (y2-y1)/(x2-x1). Is that what you're looking for?

  3. #3
    Senior Member
    Join Date
    Jun 2000
    Posts
    911
    To get the most control of the movement between two points try using vectors. General form for a vector line:
    Code:
    (x, y) = (x1, y1) + t(dx, dy)
    And "t" is called the parameter...it varies from zero to one. When it is zero the ordered pair (x,y) will be right on top of one point. When "t" equals one (x,y) will be right on top of the other point. The ordered pair (x1,y1) represents the starting position of the vector. The ordered pair (dx,dy) is the direction vector from (x1,y1) to the other point. You find the director vector like this:
    Code:
    point one = (x1, y1)
    point two = (x2, y2)
    
    Direction vector:
    
    d = (dx, dy) = (x2-x1, y2-y1)
    Now this is pretty much identical to what freakomatic proposed except it gives you a little bit more freedom in controlling your movement. Say you wanted to go straight to the middle of the line...set "t" equal to one-half and solve for (x,y). If you wanted to go to three-quarters of the line then set "t" equal to 3/4. Its really easy.

    Good luck.

  4. #4

    thanks

    Thank you very much this gives a great spring board to jump from i imagine that by changing the value of parameter in small increments i can move mc's along a path between the two points. I'll give it a shot tonight. Thanks again.

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