Graphics Programs Reference
In-Depth Information
Figure 6.6 The three rotational degrees of freedom
Exercise 6.2: Belly Up
Open the file 6_2_bellyUp.fla in the Chapter 6 folder. The script here is exactly the
same as the one you created in the previous exercise except that the z - values begin
farther back in space as can be seen in line 26. Let's add some scripting that will enable
the fish to move toward us.
Step 1: Define the distance of movement in the z-direction
Let's have all of the fish move toward us at a rate of three pixels every frame. For more
complicated motion, we might want to define a separate function, but for now we'll just
add a line to the placeObj() function. What we need is a variable dz that defines the
distance each object will move in the z - direction. Since we want the fish to come toward
us, this number has to be negative. Add the line shown below.
21
22
23
24
25
26
27
28
function placeObj()
{
// pick a random point in 3D space
thisObj.x = Math.random() * 600 - 300; // -300 < x < 300
thisObj.y = Math.random() * 400 - 200; // -200 < y < 200
thisObj.z = Math.random() * 300 // 0 < z < 300
thisObj.dz = -3; // movement in the z-direction
}
 
Search WWH ::




Custom Search