Atan2 « Actionscript Programming « Flash Tutorials

Home
Flash Tutorials
1.Actionscript Programming
2.Animals
3.Animation
4.Colors
5.Design
6.Effects
7.Game Cartoon
8.Humans
9.Models
10.Nature
11.Operations
12.Shapes
Flex
Flash / Flex / ActionScript
Flash Tutorials » Actionscript Programming » Atan2 

1. Atan2 Rotation in Actionscript | lashf.com    lashf.com

Atan2 Rotation in Actionscript | lashf.comIn this tutorial, I'm going to show you how to program the tank rifle so that it changes its rotation according to where your mouse is. It's good to know the little piece of code that makes the effect possible since it comes in really handy in many kinds of Flash applications, mostly in games, but not only. For instance, I saw an example of this code "in action" on one Flash website on which there was an object that kept turning towards my mouse. Anyway, to achieve this effect, I'm not going to need to use Sine or Cosine. Rather, I'm going to go a much simplier way using atan2 function. To evaluate an angle using this function, you only need to provide Flash with y and x coordinates. After that, Flash will compute and return the angle, measured in radians. Our job then will be only to convert these radians to degrees. Alright, why not have a look at how the atan2 function looks before we start?

java2s.com  |  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.