Jump to Main Content
Jump to Main Content

BlinkScript View Navigation Code Example



Description


This code example shows how to set up view navigation and how to lock the X and Y axis. All the code and assets are in the projects Scripts directory. You can download the project using the link above.

PostWorld.js


// Turn on debug so that Chat.printDebug() and Chat.dump() work
Chat.debugOutput = true;

// Display the stats panel in the bottom left corner of screen
Application.statsVisible = true;

// Turn on collisions, but allow the user to turn it off
Actor.setCollisionSetting( true, false );

// Turn on gravity, but allow the user to turn it off
Actor.setGravitySetting( true, false );

// Show the avatar
Actor.showAvatar  = false;

// Show the chat panel
Application.chatPaneVisible = true;

// Set ambient light for the scene
Scene.ambientLightColor = Color(0.5, 0.5, 0.5, 0);

// Create a point light over the oger head to give meanacing look
var oPointLight = Scene.createPointLight( "SceneLight" );
oPointLight.position = Vector( 0, 600, -500 );

// Create the floor
var oGround = Scene.createGround( "MainFloor", "RustySteel", 3000.0, 3000.0, true );

// Create a Skydome
oSkyDome = Scene.createSkyDome();
oSkyDome.materialName = "CloudySky";
oSkyDome.curvature = 5;
oSkyDome.tiling = 8;
oSkyDome.distance = 4000;
oSkyDome.enable = true;

// Add the Ogre head
oHeadEntity = Scene.createEntity( "OgreHead", "ogrehead.mesh" );
oHeadNode = Scene.createSceneNode( "OgreHeadNode" );
oHeadNode.attachObject( oHeadEntity );
oHeadNode.position = Vector( 0, 100, -500 );

// Set the navigation style to View
Actor.navigationStyle = Actor.NAVIGATION_STYLE_VIEW;

// Set the scene node that will be viewed
Actor.navigationNode = oHeadNode;

// Create a keyboard event listener
this.oKeyListener = new Object();
this.oKeyListener.onKeyDown = function()
{
	if ( Key.isKeyDown( Key.KEY_X ) )
		Actor.lockXAxis = !Actor.lockXAxis;

	if ( Key.isKeyDown( Key.KEY_Y ) )
		Actor.lockYAxis = !Actor.lockYAxis;
}

// Add the key listener
Key.addListener( this.oKeyListener );

// Print instructions
Chat.print( "Press X to Lock/Unlock movement on X Axis" );
Chat.print( "Press Y to Lock/Unlock movement on Y Axis" );
Chat.print( "Press Space Bar to reset" );



Related BlinkScript Examples
?????? ?????? ?????? ??????