Advertisement
Mackan90096

FPS Thing

Dec 5th, 2014
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var createScene = function () {
  2.    
  3.     // This creates a basic Babylon Scene object (non-mesh)
  4.     var scene = new BABYLON.Scene(engine);
  5.  
  6.     // This creates and positions a free camera (non-mesh)
  7.     var camera = new BABYLON.FreeCamera("camera1", new BABYLON.Vector3(0, 5, -10), scene);
  8.  
  9.     // This targets the camera to scene origin
  10.     camera.setTarget(BABYLON.Vector3.Zero());
  11.  
  12.     // This attaches the camera to the canvas
  13.     camera.attachControl(canvas, true);
  14.     scene.gravity = new BABYLON.Vector3(0, -1, 0);
  15.    
  16.  
  17.     // This creates a light, aiming 0,1,0 - to the sky (non-mesh)
  18.     var light = new BABYLON.HemisphericLight("light1", new BABYLON.Vector3(0, 1, 0), scene);
  19.  
  20.     // Default intensity is 1. Let's dim the light a small amount
  21.     light.intensity = 1;
  22.  
  23.     // Box
  24.     /*var box = BABYLON.Mesh.CreateBox("box",5,scene, false);
  25.     //box.position.y = 10;
  26.     box.position.x = 10;
  27.     box.position.z = 10;
  28.     box.checkCollisions = true;
  29.     box.applyGravity = true;*/
  30.  
  31.     // Our built-in 'sphere' shape. Params: name, subdivs, size, scene
  32.     //var box = BABYLON.Mesh.CreateBox("box", 100, scene);
  33.     var skybox = BABYLON.Mesh.CreateBox("skyBox", 1000.0, scene);
  34.     var skyboxMaterial = new BABYLON.StandardMaterial("skyBox", scene);
  35.     skyboxMaterial.backFaceCulling = false;
  36.     skybox.material = skyboxMaterial;
  37.     skybox.infiniteDistance = true;
  38.     skyboxMaterial.diffuseColor = new BABYLON.Color3(0, 0, 0);
  39.     skyboxMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  40.     skyboxMaterial.reflectionTexture = new BABYLON.CubeTexture("textures/skybox", scene);
  41.     skyboxMaterial.reflectionTexture.coordinatesMode = BABYLON.Texture.SKYBOX_MODE;
  42.    
  43.     // Ground
  44. var ground = BABYLON.Mesh.CreateGround("ground", 100, 100, 100,scene);
  45. var groundMaterial = new BABYLON.StandardMaterial("ground", scene);
  46. groundMaterial.diffuseTexture = new BABYLON.Texture("textures/ground.jpg", scene);
  47. groundMaterial.diffuseTexture.uScale = 6;
  48. groundMaterial.diffuseTexture.vScale = 6;
  49. groundMaterial.specularColor = new BABYLON.Color3(0, 0, 0);
  50. ground.position.y = -2.0;
  51. ground.material = groundMaterial;
  52.     //var roof = BABYLON.Mesh.CreateGround("roof", 1000, 1500, 1000, scene);
  53.    
  54.     // Move the sphere upward 1/2 its height
  55.     //skybox.position.y = 1;
  56.    
  57.     scene.collisionsEnabled = true;
  58.     camera.checkCollisions = true;
  59.    
  60.     ground.checkCollisions = true;
  61.  
  62.     camera.keysDown = [83];
  63.     camera.keysLeft = [65];
  64.     camera.keysRight = [68];
  65.     camera.keysUp = [87];
  66.     camera.speed = 1;
  67.     camera.applyGravity = true;
  68.    
  69.     window.onclick = function(e){
  70.         var rotx = camera.rotation[x];
  71.         var roty = camera.rotation[y];
  72.         var bullet = BABYLON.Mesh.CreateBox('bullet', .2, scene);
  73.     }
  74.    
  75.     return scene;
  76.  
  77. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement