В основном я пытаюсь получить 3D-куб в направлении, в котором находится мышь. Это почти что есть, но сейчас это не рендеринг куба, который он делал хорошо, прежде чем добавить этот код:three; js: Ошибка доступа к объекту
cube.look(xTarget, yTarget);
, который дает эту ошибку:
Uncaught TypeError: Cannot read property 'look' of undefined`
это делая cube
объект недоступен, почему это? (... по крайней мере, вот что я считаю проблемой). Что я здесь делаю неправильно?
Вот соответствующие ЯШ:
Cube.prototype.updateBody = function(speed){
this.box.rotation.y += (this.tBoxRotY - this.box.rotation.y)/speed;
this.box.rotation.x += (this.tBoxRotX - this.box.rotation.x)/speed;
this.box.position.x += (this.tBoxPosX-this.box.position.x)/speed;
this.box.position.y += (this.tBoxPosY-this.box.position.y)/speed;
this.box.position.z += (this.tBoxPosZ-this.box.position.z)/speed;
}
Cube.prototype.look = function(xTarget, yTarget){
this.tBoxRotY = rule3(xTarget, -200, 200, -Math.PI/4, Math.PI/4);
this.tBoxRotX = rule3(yTarget, -200,200, -Math.PI/4, Math.PI/4);
this.tBoxPosX = rule3(xTarget, -200, 200, 70,-70);
this.tBoxPosY = rule3(yTarget, -140, 260, 20, 100);
this.tBoxPosZ = 0;
}
function loop() {
render();
var xTarget = (mousePos.x-windowHalfX);
var yTarget= (mousePos.y-windowHalfY);
console.log('Mouse X position: ' + xTarget +', Y Target = '+yTarget);
cube.look(xTarget, yTarget);
requestAnimationFrame(loop);
}
является корректной ссылкой plunker? Функция цикла не имеет cube.look. –
Да, это в строке 92: 'Cube.prototype.look = function (xTarget, yTarget) {....};' О, подождите, строка в функции цикла находится в строке 149. –