Director Tutorials


Camera Control

Creating and Controlling Cameras

This tutorial builds on the last. So, you will need your completed Director file. If you want to download the completed one, it is available here (3Denv_charMov.dir).

1. Open the movie and open the scene control behavior.

2. Add the following to the top of the script:
property pSprite -- reference to 3D sprite

3. Add the following to the start of the beginSprite handler.
pSprite = sprite(me.spriteNum)

4. Add the following to the end of the beginSprite handler (after createLight).

5. Add the following to the script (after the createLight handler).


-- create 2 new cameras
frontCam = p3Dmember.newCamera("frontCam")
characterCam = p3Dmember.newCamera("characterCam")

-- frontCam settings
-- set up the camera's vertical viewing angle
frontCam.fieldOfView = 35

The fieldOfView is the vertical viewing angle of the camera, indicated by the angle formed by two rays: one drawn from the camera to the top of the projection plane, the other drawn from the camera to the bottom of the projection plane.

If using Director 8.5, use projectionAngle instead of fieldOfView.

-- position the camera
frontCam.transform.position = vector(150,-340,170)

The default position of any newly created camera is vector (0,0,250).

-- set rotation of camera
frontCam.transform.rotation = vector(60,0,30)

The default rotation of any newly created camera is vector (0,0,0).

The above numbers were my experimental variations of a camera set up in 3DS Max. Typically, it's easier to set up your cameras in your 3D modelling software. Here we're looking at the Lingo associated with camera properies.

-- characterCam settings - correspond position
-- of the camera to that of the character
characterCam.transform.position = \

-- set rotation of camera
characterCam.transform.rotation = vector(70,0,180)

We rotate camera 180 degrees about 'z' axis so it points from behind the character, and 70 degrees about the 'x' axis so it points slightly to the ground. A rotation of 90 degrees about the 'x' axis points the camera directly forward, greater than 90 is points up.

-- move camera to behind and above the character

-- set the camera of the sprite to the frontCam ="frontCam")

-- make cameras children of the character model
pCharacter.addChild(frontCam, #preserveParent)
pCharacter.addChild(characterCam, #preserveParent)


By making the cameras childeren of the character model, the cameras will move with the model. So when you play the movie, the character will always stay in the middle of the scene and the environment will appear to move.

6. Now we have created and set up the 2 cameras, we'll create a script to switch between them. Add the following statement to the keyDown handler.
if keypressed("c") then changeCamera

7. Next, you guessed it, we create the changeCamera handler. Add the following to the script:


-- check the sprites camera and switch
if = \
.camera("characterCam") then ="frontCam")
else ="characterCam")
end if


8 . Play the movie and test what you just created.
You can download the completed movie from here.