3. I'll explain what this code means, because without understanding it you're really not much better off.
- The first line gets the distance between the movie clip on the stage and the mouse position, both x and y, and then calculates the angle of the imaginary line between the movie clip registration point and the mouse position (this detail's in other tutorials on here as well, so check on them if you're not sure about this) This will be useful in making the movie clip rotate.
- The problem with this first line is that it converts the angle into radians, an alternative form of angle measurement to degrees. We need to convert it into degrees if we're going to be able to make the movie clip rotate. That's what the second line of code does.
- The next part measures the distance between a) the movie clip registration point and the x position of the mouse, and b) the movie clip registration point and the y position of the mouse, telling us how far away the mouse is from the movie clip.
- The next 2 lines take those distances we just worked out, and turn them into fractions of their former selves, because we don't want the movie clip moving quite so fast. We only want it to move about 5 pixels per second as a maximum. Dividing it by 20 is a fair speed, although you can mess with this if you like.
- The last lines just add the movement speed variables onto the movie clip's position, so it moves. Otherwise it doesn't move. It also adds the myDegrees rotation variable we spent precious keystrokes gathering and makes the movie clip rotate to match the position of the mouse. Enjoy! If anyone has any expansions or ideas for this feel free to email me – hithere54@hotmail.com |