0

So, I've loaded my scene I made in Blender into Babylonjs, and it's producing some interesting effects. Basically, I am trying to apply gravity and such to the scene, move the player to it's proper location, and make the entire scene lit and visible, but none of that is working. This is the script:

var BABYLON;
var canvas = document.getElementById('gamecanvas');
var engine = new BABYLON.Engine(canvas, true);
var player_height = 2;
var player_speed = 1;
var player_inertia = 0.9;

function INIT_GAME(){
    BABYLON.SceneLoader.Load('Scenes/', 'zombie_map.babylon', engine, function(newScene){
        var scene = newScene; 
        var light = new BABYLON.PointLight('light', new BABYLON.Vector3(0,0,10), scene);
        var player = new BABYLON.FreeCamera('player', new BABYLON.Vector3(1,1,1), scene);
        scene.activeCamera = player;
        scene.activeCamera.attachControl(canvas, true);
        scene.enablePhysics();
        scene.setGravity(new BABYLON.Vector3(0, -10, 0));
        player.ellipsoid = new BABYLON.Vector3(1, player_height, 1);
        player.checkCollisions = true;
        player.applyGravity = true;
        player.keysUp = [87];
        player.keysDown = [83];
        player.keysLeft = [65];
        player.keysRight = [68];
        player.inertia = player_inertia;
        player.speed = player_speed;
        newScene.executeWhenReady(function(){
            engine.runRenderLoop(function(){
                newScene.render();
            });
        });
    });

canvas.height = window.innerHeight;
canvas.width = window.innerWidth;
canvas.requestPointerLock = canvas.requestPointerLock || canvas.mozRequestPointerLock;
canvas.requestPointerLock();

window.addEventListener('resize', function(){
    engine.resize();
});

}

The questions I have are:

  1. How do I make the render distance higher, so that I can view the whole scene?
  2. Why are none of my scene properties working (gravity, movement, etc.)?
gman
  • 100,619
  • 31
  • 269
  • 393
Taylor Brown
  • 89
  • 1
  • 1
  • 9
  • For the first question, you can change the `position` property of the camera. – ConnorsFan Apr 03 '16 at 01:21
  • I have tried that, and it doesn't change the position at all, adding to the strangeness – Taylor Brown Apr 03 '16 at 01:58
  • You could try to reproduce your problem on Babylon's playground (http://www.babylonjs-playground.com/). If you save your test, other people can access it and debug it. You can also consult their forum (http://www.html5gamedevs.com/forum/16-babylonjs/). – ConnorsFan Apr 04 '16 at 00:32

1 Answers1

0

Your player camera should be set as the active camera:

var player = new BABYLON.FreeCamera('player', new BABYLON.Vector3(1,1,1), scene);
scene.activeCamera = player;
scene.activeCamera.attachControl(canvas, true);
ConnorsFan
  • 70,558
  • 13
  • 122
  • 146
  • The camera movement now works, but the rest of the properties still don't work. – Taylor Brown Apr 03 '16 at 19:35
  • Not easy for me to test those properties (checkCollisions, applyGravity, etc.). You say that camera movement works, do the keys work? – ConnorsFan Apr 03 '16 at 22:35
  • Yes, the camera is movable, but when I press a movement key, it moves downwards only. The scene still has no gravity or collisions. – Taylor Brown Apr 04 '16 at 04:00