0

I have the problem, that my three.js scene fails to render as soon as i create a PointerLockControls object. I have absoulute no clue what the issue could be.

main.js:

const THREE = require("three");
var PointerLockControls = require('three-pointerlock');
//utils
import detect from "./detect"
import dialogs from "./dialogs"
import calc from "./calc"
import {Player} from "./charackters"


//3D stuff
import world from "./world"

//Scene creation
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 1000 );

var controls = new PointerLockControls(camera);

camera.position.y = -50;
camera.position.z = 40;
camera.rotation.x = calc.rad(90);


//WebGL Renderer
var renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor(0x000000);
document.body.appendChild( renderer.domElement );

world.drawFloor(scene, THREE);
var cGeo = new THREE.BoxGeometry(10,10,10);
var cTexture = new THREE.MeshNormalMaterial();
var Cube = new THREE.Mesh(cGeo, cTexture);
scene.add(Cube);


//tick function
var clock = new THREE.Clock(true);
function animate() {
    requestAnimationFrame(animate);
    controls.update(clock.getDelta);
    renderer.render( scene, camera );
}

if(detect.webgl()){
  animate();
}else{
  dialogs.error("Your browser does not support WebGL. Please install a modern Browser such as Google Chrome or Mozilla Firefox to play AlphaWars!", "Warning:")
} 

if you need any of my additional files please comment.
Thanks in advance.

1 Answer 1

1

Maybe you use the PointerLockControls in a wrong way. You should add scene.add( controls.getObject() ); after var controls = new PointerLockControls(camera); because PointerLockControls object has a attribute pitchObject and you should add it into scene.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.