
The code of the next three lessons is based (we made some modifications)in studies from Anthony Rowe and Gareth Bushell from the design group: squid soup.
Our basic idea (a little different from their ideas - they are creating a car running) is to create 1st person web worlds. Funny games... Or art galleries... Or virtual malls...
In this kind of world the "point-of-view" is the eye of the user, the eye of the player - if we have a game.
In multiuser 3D worlds we have the avatar that represents the player. In the future we will try to create multiuser worlds but now, we will create an invisible avatar and put a camera in his eyes.
In this lesson we will only create the avatar and try to learn how to move him. The camera will stay fixed, looking for the world. In the next lesson, the camera will go to the eyes of the avatar.
I hope you have readed the Help of 3ds max. We will not talk about the basics.
I hope you have readed also the Help of Director.
If you did this things it's possible that you discover a terrible fact: in Director, the positive Y axis points up; in 3ds max the positive axis points away from you and the positive Z points up!.
We choose the traditional Cartesian standard and we will need to make some "magic", transforming the max views.

It's not easy to do this every project and our sugestion is: the creation of a basic world that will be open and re-saved in the begining of each project.
My sugestion also is that: in every lesson of this tutorial you try to make the exercice that is our 3D demo. In this lesson, the world is only a floor, and something that you can imagine like a primitive, basic avatar (a red box).
Important: the avatar needs to have a name: avatar, that will be used inside Director.
We need to export the 3ds max world to a format that Director can import, a .W3D file. In the Discreet site we can download (it's free) a plugin that do it. It's very easy to install and you need to read the documentation.
When we import a .W3D file, it goes to the cast. In our case we will change its name to: world.
A 3D world in Director is a sprite of a normal Director "movie", but the movie is in loop repeating the same frame forever :-)
We can glue a script to the world/movie. This script will run when the movie starts.
Scripts not glued to frames or to the world can be created and need to be called by one of this scripts.
To create a script we can open a window selecting Window | Script. To create another script we use the + button.
global myworld
global avatarobj, cameraobj
on preparemovie me
setupobjects -- look how we put comments in the script
end
on setupobjects
clearglobals
member("world").resetworld()
myworld = member("world")
avatarobj = new(member("avatarobj").script)
cameraobj = new(member("cameraobj").script)
end
The name of the imported world will be myworld in the script - could be another....
We are creating two external scripts: avatarobj and cameraobj that is called here.
The cameraobj script:
property mycam --the camera global avatarobj,myworld on new me mycam = myworld.camera[1] mycam.projectionangle = 40 mycam.transform.position=vector(-2.88,-150.0, 41.20) - position of the camera mycam.transform.rotation=vector(80.00,0.43, -3.61) return me end
A block new is executed in the first time when the script is called.
Here we define mycam using a basic object/array of Director.
We said that a 3D world is a sprite in a frame in loop. The script glued to this frame (can be the frame 10 if we create an 2D introduction) .
global avatarobj on exitFrame me go the frame end on prepareframe me control avatarobj - go to method control of script avatarobj end
The statement in the first method/event creates the loop.
When the frame is "beginning" the part control - we will see it soon - of the script avatarobj is executed. This is the more important part of our application.
The avatarobj script:
property fwvect, upvect, distanceforward, steer
global myworld
on new me
upvect = vector(0,1,0) -- up is Y
fwvect = vector(1,0,0)
distanceforward = 0
steer = 0
return me
end
on control me
if keypressed(126) then --uparrow
acc = 0.025
else
acc = 0
end if
if keypressed(124) then --rightarrow
turn = 2
else
if keypressed(123) then --leftarrow
turn = -2
else
turn = 0
end if
end if
distanceforward = distanceforward + acc - 0.015
if distanceforward < 0 then distanceforward = 0
if keypressed(125) then distanceforward = - 0.8
if distanceforward > 0.8 then distanceforward = 0.8
steer = (steer + turn)*0.8
if steer < -5.0 then steer = -5.0
if steer > 5.0 then steer = 5.0
-- turning the avatar
myworld.model("avatar").transform.rotate(myworld.model("avatar").worldposition, upvect, steer, #self)
-- translating the avatar
rotator = transform()
rotator.rotate(vector(0,0,0), upvect, steer)
fwvect = rotator*fwvect
movement = ( fwvect*distanceforward )
myworld.model("avatar").translate(movement ,#world)
end
Our target is: when the player press one arrow key (123 or 124 or 125 or 126) the avatar makes a translation or a rotation.
Director has two methods for this:
obj.transform.rotate(position,axis,angle,#self) obj.translate(fwvect*distancefoward, #world)
self and/or world are the referenced system of coordinates.
The basic axis : Y, for rotation is defined by a vector: vector(0,1,0) .
translate needs a vector that defines the direction (vector(1,0,0)), multipled by the increment in distance.
The world needs to be draged from the cast to the stage (to the frame that has the loop script). Only this :-)
We can change the background color and the ambient light in the world, using the Property Inspector
We manage the world in Director like an image in a movie: we can enlarge it etc. etc. To test the world in desing time: run the movie.
Save , export etc. like an usual movie. Look and play using the arrow keys to move the "avatar". This is a little confuse because we don't know "where he is looking". In the next lesson we will learn how to fix this. :
PREVIOUS LESSON NEXT LESSON T. CONTENTS HOMEPAGE
