var leftKey = 72;
var rightKey = 74;
document.onkeydown = checkKey;
function checkKey(e){
e = e || window.event;
if(e.keyCode === leftKey){
car.position.z = car.position.z -10;
}
if(e.keyCode === rightKey){
car.position.z = car.position.z +10;
}
}
car.position.x ++;
你好,我正试图让汽车向前推进游戏的每次更新。但代码'car.position.x +++;'抛出错误'TypeError:无法读取未定义的属性'位置'。我怎样才能解决这个问题?谢谢!
myColladaLoader = new THREE.ColladaLoader();
myColladaLoader.options.convertUpAxis = true;
myColladaLoader.load( 'car.DAE', function ( collada ) {
// Her the dae in a global variable.
car = collada.scene;
// Position your model in the scene (world space).
car.position.x = -1850;
car.position.y = 0;
car.position.z = 0;
// Scale your model to the correct size.
car.scale.x = car.scale.y = car.scale.z = 0.2;
car.updateMatrix();
// Add the model to the scene.
scene.add( car );
} );
在上面添加汽车!
答案 0 :(得分:0)
这里的问题显然不是范围错误,而是javascript渲染功能在汽车甚至实现之前更新。 解决这个问题的方法是推迟前进的车辆直到那里。