A Flash Developer Resource Site

1. ## Trigonometry

I am making my own scripted camera.

The idea behind a scripted camera is that you just move it anywhere you want on the screen, and, once the movie is compiled, a script in it makes that part of the movie visible. The idea comes from this web page.

I've already gotten it to be able to go left, right, up, down, and resize. However, I also want it to be able to rotate, which is something that even the guy who invented it can't figure out. Unfortunately, that requires trigonometry, and I can't get it to work in Flash.

Once horizontal and vertical movements, and resizing, have been taken care of, I think all the math that's left is this:

If I've got it right (I might not), and that's how to solve it, I myself could do it with a pencil and paper, but I can't seem to get Flash to do the trig correctly, at least not with all four quadrants with the same code.

The FLA file with my code in it is HERE.

I feel like I'm so close to figuring it out. I know ActionScript, and I know Trig, just... not both at the same time.

2. I often attept things I cant do. lol. What exactly are you trying to figure out. I normally just write down tre maths. and then translate it into stes in flash.

3. Well, if you go to the link I provided, it'll explain the basic idea behind a scripted camera. (Mine is a little different, in that the (0,0) point is in the upper left, and that it doesn't turn invisible because it has the controlls for the movie in it.)

Basically, having the initial x and y cordinates, the _x and _y, I figure out what the coordinates should be after the rotation, the _x and _y, by using the angle of rotation, _rotation, and the distance from the (0,0) point of the camera to the (0,0) point of the _root.

Either my math is wrong, or my scripting is wrong, but I can't get it to work correctly.

4. Basically that approach should be correct.
I just fix some positve/negative things.

5. Thank you so much!!!

I had messed around with the +/- signs, but I was never able to get it to work in all four quadrants. I guess it's because of your changing my Math.asin(_parent._y/r) into Math.atan2(y, x). I would never have though of that.

Side note:
Hmm, calculating trigonometry seems to take a chunk out of my CPU I'd rather save for other calcutations. I think I'll make the symbol into a component, and make it able to be used either with or without the trig.

6. If you dont insist on Math, and _parent is the _root, then use localToGlobal make the script very simple.
code:
```this.onEnterFrame = function() {
_parent._yscale = 10000/(this._yscale);
_parent._xscale = 10000/(this._xscale);
_parent._rotation = -this._rotation;
var point = {x:0, y:0};
this.localToGlobal(point);
_parent._x-=point.x;
_parent._y-=point.y;
};```

7. HEY, WOW!!!

I didn't know about that function! Thanks!

So, that's, how may hours of my life I've wasted trying to get that trig to work, when all I had to do was use localToGlobal()?

Oh, and, by the way, I've discovered that the code should be
Code:
```function camControl():Void {
_parent._yscale = 10000/(this._yscale);
_parent._xscale = 10000/(this._xscale);
_parent._rotation = -this._rotation;
var point = {x:0, y:0};
this.localToGlobal(point);
_parent._x-=point.x;
_parent._y-=point.y;
}
camControl();
this.onEnterFrame=camControl;```
to get it to work on most keyframes.

#### Posting Permissions

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

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap