Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot get the FirstPersonControls in three.js working

i'm trying this:

controls = new THREE.FirstPersonControls(camera);

controls.movementSpeed = 1000; controls.lookSpeed = 0.125; controls.lookVertical = true;

it didn't work, From here i found out that i need to update the control with time delta:

var clock = new THREE.Clock();

controls.update( clock.getDelta() );

but I get undefined is not a function error for THREE.Clock()

can you please point me to working demo/tutorial with FirstPersonControls, or just tell me whats wrong?

Thanks!!

like image 805
Sergej Popov Avatar asked Nov 09 '11 10:11

Sergej Popov


2 Answers

Have you tried simply calling controls.update(); (withough passing a delta) ?

I've just tried using the class by copying a bit of code from the misc_sound.html example. So in init():

controls = new THREE.FirstPersonControls( camera );

                controls.movementSpeed = 70;
                controls.lookSpeed = 0.05;
                controls.noFly = true;
                controls.lookVertical = false;

and in render():

controls.update();

Update

As Todd points out, in newer versions, a delta time argument needs to be supplied:

controls.update(delta);
like image 168
George Profenza Avatar answered Nov 03 '22 17:11

George Profenza


Please note that in R49, this api now requires the 'delta' on the update call. The delta needs to be the millisecond displacement since last update, which should be passed out through the requestAnimationFrame callback.

http://paulirish.com/2011/requestanimationframe-for-smart-animating/

like image 45
deepelement Avatar answered Nov 03 '22 16:11

deepelement