It isn't hard to make the eyes follow the mouse but it does make use of some math to get the angles of rotation.
The Movie file
Open the provided bird file. There's the birds body and and 2 plain white eyeballs
Give the left eye an instance name of eye1 and the right eye an instance name of eye2
Double click on one of the eyeballs. Put a black dot to the left of the center of the eye. Notice that the other eye changes as well because they are made from the same movieclip.
What's it got to do with math?
We want the eyes to rotate in the direction of the mouse position so its based on trigonometry.
The Movie file
Open the provided bird file. There's the birds body and and 2 plain white eyeballs
Give the left eye an instance name of eye1 and the right eye an instance name of eye2
Double click on one of the eyeballs. Put a black dot to the left of the center of the eye. Notice that the other eye changes as well because they are made from the same movieclip.
What's it got to do with math?
We want the eyes to rotate in the direction of the mouse position so its based on trigonometry.
The Code
Now you are ready to add your actions code to frame 1 of the actions layer.
We can calculate angle A if we get distances a and b, to get this we can use the following code to frame one of our movie:
a = eye._y-_ymouse;
b = eye._x-_xmouse;
Now, to turn those distances into angle A we can use this code:
angleA = Math.atan2(a, b);
This gives you the angle in “radians”, but we need it in degrees. To convert angleA into degrees we use this line:
degrees = angleA/(Math.pi/180);
Now we can tell the eye to rotate in degrees:
setProperty ("eye", _rotation, degrees);
The movie needs to repeatedly look at the mouse position to move the eye to its new position. To do this, put a keyframe on frame 2 and add the following frame code to the second frame of your main movie:
gotoAndPlay (1);
When the movie plays, the playhead gets to frame 2 and is sent back to 1 to play again, and again, and again....
Now if you test your movie the left eye should turn around and follow your cursor where ever it goes.
To get the second eye spinning (eye2) you simply copy the code and replace whereever it says "eye1" with "eye2". Here is the finished code that should be in frame 1 of your actions layer:
a = eye1._y-_ymouse;
b = eye1._x-_xmouse;
angleA = Math.atan2(a, b);
degrees = angleA/(Math.pi/180);
setProperty ("eye1", _rotation, degrees);
a2 = eye2._y-_ymouse;
b2 = eye2._x-_xmouse;
angleA2 = Math.atan2(a2, b2);
degrees2 = angleA2/(Math.pi/180);
setProperty ("eye2", _rotation, degrees2);
If you'd like you can copy and paste the above code into frame 1. Dont forget to put in the right code for frame 2 as well. gotoAndPlay (1);
We can calculate angle A if we get distances a and b, to get this we can use the following code to frame one of our movie:
a = eye._y-_ymouse;
b = eye._x-_xmouse;
Now, to turn those distances into angle A we can use this code:
angleA = Math.atan2(a, b);
This gives you the angle in “radians”, but we need it in degrees. To convert angleA into degrees we use this line:
degrees = angleA/(Math.pi/180);
Now we can tell the eye to rotate in degrees:
setProperty ("eye", _rotation, degrees);
The movie needs to repeatedly look at the mouse position to move the eye to its new position. To do this, put a keyframe on frame 2 and add the following frame code to the second frame of your main movie:
gotoAndPlay (1);
When the movie plays, the playhead gets to frame 2 and is sent back to 1 to play again, and again, and again....
Now if you test your movie the left eye should turn around and follow your cursor where ever it goes.
To get the second eye spinning (eye2) you simply copy the code and replace whereever it says "eye1" with "eye2". Here is the finished code that should be in frame 1 of your actions layer:
a = eye1._y-_ymouse;
b = eye1._x-_xmouse;
angleA = Math.atan2(a, b);
degrees = angleA/(Math.pi/180);
setProperty ("eye1", _rotation, degrees);
a2 = eye2._y-_ymouse;
b2 = eye2._x-_xmouse;
angleA2 = Math.atan2(a2, b2);
degrees2 = angleA2/(Math.pi/180);
setProperty ("eye2", _rotation, degrees2);
If you'd like you can copy and paste the above code into frame 1. Dont forget to put in the right code for frame 2 as well. gotoAndPlay (1);
See if you can figure out what to do to get a second bird working.
|
|
Inspired by eTheory AS2