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 ++;
Greetings, I am attempting to move the car forward during each game update. However, when I try 'car.position.x ++;', it results in the error 'TypeError: Cannot read property 'position' of undefined'. Any suggestions on how to resolve this issue? Thank you!
myColladaLoader = new THREE.ColladaLoader();
myColladaLoader.options.convertUpAxis = true;
myColladaLoader.load( 'car.DAE', function ( collada ) {
// Storing the dae model in a global variable.
car = collada.scene;
// Positioning the model in the scene (world space).
car.position.x = -1850;
car.position.y = 0;
car.position.z = 0;
// Scaling the model to the correct size.
car.scale.x = car.scale.y = car.scale.z = 0.2;
car.updateMatrix();
// Adding the model to the scene.
scene.add( car );
} );
Car added successfully above!