AN AUTOMATIC DOOR - DISTANCETO AND INTERPOLATETO


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:
kitb.dir - 52kb kitb.max - 197 kb
You can see a demo of the world at: 3dD Basic Kit demo-world

When you are near some automatic door, it opens.This fact has two parts:

The usual triggers in the 3D virtual life are:

But Lingo has a method that let us know (returns) how far is the distance between the avatar an some object; is the method: distanceTo.

Better to say: false distance. Look at the figure (the avatar and world are from out tutorial about ADOBE's Atmosphere that has the same method):

or more schematicaly:

But this doesn't matter. The important is that we can capture the "distance" (proximity) between two objects A and B using the lines of code:

  posA = myworld.model("A").worldposition 
  posB = myworld.model("B").worldposition
  dist = posA.distanceTo(posB)

In our exercice we will open a door using the proximity from the avatar to a door.

But how to open the door?

Lingo has another method that we can use to do this: interpolateTo

If we have two objects A and B, using the lines of code:

 
    tA = myworld.model("A").transform
    tB = myworld.model("B").transform
    tA.interpolateTo(tB, n)
     
inside a loop, A will go to the B transform (position + rotation) runing n% of the distance from A to B in each timestep.

Using the 3dD Basic Kit we create in 3ds max a house and two doors: a real, in the closed position, and a "ghost" in the open position.

The "distance" tested is between the avatar and the door.

Using the 3dD Basic Kit you need to add some lines of code in the avatatobj script. In the new method:

  
  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 
  
  doorg = myworld.model("doorg") -- the ghost door
  doorg.visibility = #none
 

In the control method:

  
  pav = myworld.model("avatar").worldposition 
  pdoor = myworld.model("door").worldposition
  dist = pav.distanceTo(pdoor)
   
  if(dist<70) then
    tdoor = myworld.model("door").transform
    tdoorg = myworld.model("doorg").transform
    tdoor.interpolateTo(tdoorg,5)
   end if

Play the demo (have sound) trying to go inside the house. You can jump the window :-)




PREVIOUS LESSON NEXT LESSON
T. CONTENTS HOMEPAGE