babylonjs 设置面板位置_场景渲染在Babylonjs中很奇怪

bd96500e110b49cbb3cd949968f18be7.png

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:

How do I make the render distance higher, so that I can view the

whole scene?

Why are none of my scene properties working (gravity, movement, etc.)?

解决方案

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);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值