
DOWNLOAD THE 3dD BASIC KIT
The 3dD Basic Kit is a FREE basic scenery where you can make the exercices of our tutorial.
The kit has a basic 3ds max world: kitb.max that is only a floor
and a Director world : kitb.dir. The movie has four scripts: setupscript avatarobj cameraobj and timestep
Normaly you will put YOUR code in the avatarobj script using one of the two methods:
new - for one-time execution code or control - for code inside the timestep-loop.
In our lessons we will use the 3dD Basic Kit like a pre-requirement for the exercices
and make references to it.
To download the files right-click the links, saving the target in your PC:
Everybody likes to open doors in games. And this is a "pivoting door"!It has a hinge and will be open by a click in the red button.
The first thing we need to learn is how to detect a click in a 3D object.
Lingo has a powerful method to do this: modelsUnderLoc
We need to create a sprite-script in the sprite that is "the world" (click in the score is an option to open a sprite-script). We will call this script:trigger:
global avatarobj
on mouseUp me
set=point(sprite(1).left,sprite(1).top)
pt = the mouseLoc - set
m = sprite(1).camera.modelsUnderLoc(pt, 3, #detailed)
if m.count>2 then
if m[2].model.name ="but" then
avatarobj.open=1
end if
end if
end
To understand how modelsUnderLoc works you imagine a ray (Macromedia loves rays and array of arrays...)that goes, from the camera to the point that was clicked in a "virtual window" in front of the 3D world and goes ahead to the infinitum.
It returns all the objects it bores in an array of arrays (m). Each array is for each object bored.
Our camera is inside the avatar. The "avatar" will be the first object/model. The second array is for the object clicked.
We test if the name of the object clicked is "but" (and set a flag) using:
if m[2].model.name ="but" then
avatarobj.open=1
We need to create the flag open in the avatarobj/new script. A good place to create flags and counters.
And what happens if the flag avatarobj.open is set to 1? Look to the new timestep script:
global avatarobj, cameraobj, myworld
on prepareframe me
control avatarobj
control cameraobj
--to open the door
if(avatarobj.open=0) then
sound(1).pause()
else
sound(1).play()
end if
end
on exitFrame me
if( avatarobj.open=1 AND avatarobj.t<50) then
myworld.model("door").transform.rotate(myworld.model("hin").worldposition, avatarobj.upvect, 2)
if( avatarobj.open=1 AND avatarobj.t<51) then
set avatarobj.t = avatarobj.t + 1
go the frame
end
We rotate the door using the hinge like the basic axis.
In the avatarobj/new script we define the collision and the flag and counter. The added code is:
myworld.model("house").addmodifier(#collision)
myworld.model("house").collision.enabled = true
myworld.model("house").collision.resolve = true
myworld.model("house").collision.mode = #mesh
myworld.model("door").addmodifier(#collision)
myworld.model("door").collision.enabled = true
myworld.model("door").collision.resolve = true
myworld.model("door").collision.mode = #mesh
open = 0
t=0
Play the demo (has sound).
PREVIOUS LESSON NEXT LESSON T. CONTENTS HOMEPAGE
