Game Development Reference
In-Depth Information
Cosinus and Sinus
Next, create a rule to detect the touch on the projectile. You will use the mouse
device position to constrain the position of the projectile. But you want to
constrain this position within a circle. Use the Cosine and Sine functions, as
shown in Figure 6-11.
Figure 6-11. Cosine and Sine
Cosines and Sines are trigonometric functions, meaning they are functions of an
angle, that link angles of a right triangle with the sides of this triangle. In a right
triangle, the cosine of an angle (alpha) is defined by
Cosine(alpha) = (adjacent side of the angle alpha)/(opposite side to the right
angle ---- hypotenuse)
The sine of an angle (alpha) is defined by
Sine(alpha) = (opposite side of the angle alpha)/(opposite side to the right angle
---- hypotenuse)
As you want to constrain the projectile within the circle that is defined by the
attribute MaxPower, the value you use for c will be the minimum of MaxPower
and the distance between A and B. This way the maximum value that c will be
able to take is MaxPower.
Let's implement all this.
Moving the Projectile with a Touch
Open the Scene Editor and create an Integer game attribute named
''MaxPower.'' Set a default value of 75.
 
Search WWH ::




Custom Search