dcsimg
A Flash Developer Resource Site

Page 2 of 2 FirstFirst 12
Results 21 to 23 of 23

Thread: Angles what direction is 0 degrees?

  1. #21
    Iron Chef In-Training OpethRockr55's Avatar
    Join Date
    Sep 2005
    Location
    Kitchen Stadium
    Posts
    313
    That could work... but in Flash, the coordinate system is flipped on the Y-axis, so down is positive, up negative. The X-axis is left alone. You can modify what the actual angle is read by Flash simply by flipping the axises or adding 90 degrees/PI.

  2. #22
    The Flashman earl223's Avatar
    Join Date
    Sep 2000
    Location
    Marikina City, Philippines
    Posts
    876
    Nope 0 degrees is definitely facing east ---> just like just like what blinkOK and Nialsh are saying.

    SWAK: to finally settle the issue, let's make a script that will have the "arrow" point to the direction of the mouse. Put this script on the "arrow" movieclip:
    Code:
    onClipEvent(enterFrame) {
       dx = _root._xmouse - this._x;
       dy = _root._ymouse - this._y;
       this._rotation = Math.atan2(dy,dx) * 180/Math.PI;
    }
    Before you test it, be sure that the arrow's rotation is at 0 degree. (use the transform panel) If you have your "arrow" facing up, you will see that the "east" side of the arrow will always face towards the mouse. But, if the arrow was initially facing east, then the arrow will point towards the mouse. Meaning 0 degrees is always east.
    i eat actionscripts for breakfast

  3. #23
    Quote Originally Posted by The Scotsman
    ...

    Where does he pull all this stuff from? I mean he just neglects to explain why c = -2..... I cant even understand where he gets c from in the first place, never mind why it starts -2...
    I have the same book, and at first, I was very confused at this. But after inpecting it, I think it is just the idstance formula FOILed out. Instead of writing x^2 -2xy +y^2 or what ever, he wrote the -2... first. I think that is it. I am still not sure on this though, and have been trying to some up with my own method in terms that I can understand

    {EDIT}
    AHA! I finally just sat out and tried to solve the problem on my own with pencil and paper.

    OK, so, the whole point of this is to find the distance between the two circles, and if this distance is less than both their radii combined, they are colliding. But, we want to be frame independent, so we see when a collision is going to occur by writing their relative x and y coordinates using their x and y speeds and time (in this case, time = frames).

    Circle 1:
    x1 = xl1 + xmov1t
    y1 = yl1 + ymov1t

    Circle 2:
    x2 = xl2 + xmov2t
    y2 = yl2 + ymov2t

    Looks familiar right? Ok, now these equation equal their x and y posistions right? So, since we have their coordinates, we can find the distance between them like so:

    Math.sqrt( (x2 - x1)^2 + (y2 - y1)^2 )

    So, if the distance between the two circles is equal to their radii added together, they are colliding right? So we set that equal to:

    radius1 + radius2

    Now, like it says in the book, we solve for time. Now, if you multiplied out this: (x2 - x1)^2 we would get:

    xmov2^2*t^2 + xmov1^2*t^2 - 2xmov2*xmov1*t^2 + 2xl2*xmov2*t + 2xl1*xmov1*t - 2xl2*xmov1*t - 2xl1*xmov2*t + xl2^2 + xl1^2 - 2xl2*xl1

    Phew! Now, it would look the same for the y ( (y2 - y1)^2 ) only like this:

    ymov2^2*t^2 + ymov1^2*t^2 - 2ymov2*ymov1*t^2 + 2yl2*ymov2*t + 2yl1*ymov1*t - 2yl2*ymov1*t - 2yl1*ymov2*t + yl2^2 + yl1^2 - 2yl2*yl1

    Now, notice how I've grouped this huge equations into groups. The group has a t^2 in it, the second group has just a t in it, and the third group doesn't have any t's. Now, if we were to factor a t^2 out of the first group, it would look like this:

    t^2(xmov2^2 + xmov1^2 - 2xmov2*xmov1)

    Looks familiar right? So, they do the same thing with the y's too:

    t^2(ymov2^2 + ymov1^2 - 2ymov2*ymov1)

    Now, if we factor that t^2 out of those two equation we get:

    t^2(xmov2^2 + xmov1^2 - 2xmov2*xmov1 + ymov2^2 + ymov1^2 - 2ymov2*ymov1)

    Which is what they have written where they have g*t^2 + h*t + k = 0

    this: t^2(xmov2^2 + xmov1^2 - 2xmov2*xmov1 + ymov2^2 + ymov1^2 - 2ymov2*ymov1) equals g*t^2. See???? And they did the same thing for the variables that had a t in them, and grouped them together into the letter h.

    As k goes, the reason why they subract R^2 is because remember, this is a distance equation. This whole thing has a big square root sign over it. So, in order to set this equal to 0, they square both sides, and subract the R^2.

    Hopes this helps, it helped me:
    Last edited by Mattachoo; 01-23-2006 at 03:48 PM.

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