I have a scenario where I need to add a camera to an object named car
. Following the addition of the camera, my goal is to access it through the same object. Here's what I've attempted so far:
car = {};
car.body = new Physijs.BoxMesh(
new THREE.BoxGeometry( 10, 5, 7 ),
Physijs.createMaterial(
new THREE.MeshLambertMaterial({ color: color }), .8, .2 ),
1000 );
var camera = new THREE.PerspectiveCamera(50, window.innerWidth/window.innerHeight, 1, 1000);
var pos = car.body.position;
camera.position.set(pos.x + 75, pos.y + 20, pos.z);
camera.lookAt( pos );
car.body.add(camera);
//...
// other function
var camera = car.body.camera;
However, upon testing, I encountered an error message stating
THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.
My question is whether this setup is feasible or if I should consider storing the camera(s) in a global variable or array instead?