
Our project now is the creation of a room having a door that will open when we use a key.
In the first part of the project we will not have neither the 3D key nor the Inventory. We will create the AI (the program) to work only like this: the player clicks a button and the door opens.
But first of all we need to know some secrets of the "collision system" implemented now (Blink3D alpha version 120). Some may be bugs...
We will define, before the creation of all the Physical Models, a collisionGeometryType. Included the "land" implementation, that is part of the code included in the BBGKIT!
oLandEntity.collisionGeometryType = oLandEntity.COLLISION_GEOM_TRI_SOUP; oLandEntity.createPhysicalModel();
NOTE OF THE BETA VERSION: There are some other collisionGeometryType-s but they are not working well
How the collision system works?
But if we have a door (a hole) in the wall, the "collision box" will be around ALL the wall!
So, we need to create many "independent" parts for this kind of wall (having a door). Sometimes it will be possible to include some of these parts in the "land" (may be these of the sample...). For some parts, it will not work.
The door (this is obvious) will be an independent mesh - because it will be not static.
NOTE OF THE BETA VERSION: There are a bug and the "collision box" is not dynamic. This means that when you move an object (the door in this case) it loose its collision - that remains in the old place. This will be fixed soon.
To bypass this bug we need, to disable the collision when the door opens, using something like:
door1Entity.collide= false;
If the door is closed in the future, we will change this again.
To open the door (here is a "jump" - we will explain how to create a smooth movement in the next lesson) is easy :
door1Node.translate(Vector(-500,0,0 ), oObj3Node.TRANSFORM_WORLD );
Look the complete code:
// Attach the Land
//The land here is the Ground and the convex area (3 walls)
oLandEntity = Scene.createEntity( "Land", "land.mesh" );
Scene.rootNode.attachObject(oLandEntity );
oLandEntity.fixed = true;
//Verify and add this line if it doesn't exist in the BBGKIT code
oLandEntity.collisionGeometryType = oLandEntity.COLLISION_GEOM_TRI_SOUP;
oLandEntity.createPhysicalModel();
oLandEntity.active = false;
oLandEntity.position = Vector(0, 0, 0);
// Create a point light
oPointLight = Scene.createPointLight( "SceneLight" );
oPointLight.position = Vector( 20, 300, 50 );
//Adding the left part of the wall having the door
oObjEntity = Scene.createEntity( "Obj", "wall1.mesh" );
oObjNode = Scene.createSceneNode( "ObjNode" );
oObjNode.attachObject( oObjEntity );
oObjNode.translate(Vector(0,0,0 ), oObjNode.TRANSFORM_WORLD );
oObjEntity.fixed = true;
oObjEntity.collisionGeometryType = oObjEntity.COLLISION_GEOM_TRI_SOUP;
oObjEntity.createPhysicalModel();
oObjEntity.active = true;
//Adding the right part of the wall having the door
oObj2Entity = Scene.createEntity( "Obj2", "wall2.mesh" );
oObj2Node = Scene.createSceneNode( "Obj2Node" );
oObj2Node.attachObject( oObj2Entity );
oObj2Node.translate(Vector(0,0,0 ), oObj2Node.TRANSFORM_WORLD );
oObj2Entity.fixed = true;
oObj2Entity.collisionGeometryType = oObj2Entity.COLLISION_GEOM_TRI_SOUP;
oObj2Entity.createPhysicalModel();
oObj2Entity.active = true;
//The door
oObj3Entity = Scene.createEntity( "Obj3", "door.mesh" );
oObj3Node = Scene.createSceneNode( "Obj3Node" );
oObj3Node.attachObject( oObj3Entity );
oObj3Node.translate(Vector(0,0,0 ), oObj3Node.TRANSFORM_WORLD );
oObj3Entity.fixed = true;
oObj3Entity.collisionGeometryType = oObj3Entity.COLLISION_GEOM_TRI_SOUP;
oObj3Entity.createPhysicalModel();
oObj3Entity.active = true;
//The button
oButton = GUISystem.createButton( "BtUse" );
oButton.active = true;
oButton.alwaysOnTop = true;
oButton.text = "USE ITEM";
oButton.absolutePositionX=100;
oButton.absolutePositionY=70;
oButton.absoluteWidth = 40;//HEIGHT
oButton.absoluteHeight = 180;//width
oButton.normalTextColor = Color( 0, 0, 1, 1 );//blue
oButton.onClicked = function( sWindowName){
oObj3Entity.collide= false;
oObj3Node.translate(Vector(-500,0,0 ), oObj3Node.TRANSFORM_WORLD );
}
oButton.addListener(oButton.ON_EVENT_CLICKED );
GUISystem.addChildWindow( oButton);
And the door will open. And the avatar will go in!
IMPORTANT to note that the door will open only in the world of the user that clicks the button. It's not YET a multiplayer game! We will talk about multiplayer games in the future.
PREVIOUS LESSON NEXT LESSON T.CONTENTS HOMEPAGE
