Rafay Saleem
Rafay Saleem

Reputation: 71

Object not visible when making child of a camera in three.js

I am a beginner to three.js. I am trying to make a sphere a child of my camera in my scene. But the sphere doesn't appear in the scene anywhere. I assumed that the position of the sphere is set in such a way that it is behind or above the camera so it isn't visible because it moves with the camera.

But I tried using a second camera in order to view where the object is with respect to the first camera but the sphere isn't visible anywhere in the scene.

The sphere is visible when I don't make it a child of the camera.

Is there an easier way to do it or an I missing something.

Upvotes: 0

Views: 1172

Answers (1)

WestLangley
WestLangley

Reputation: 104833

The camera must be added to the scene graph if the camera has a (renderable) child.

The camera looks down its local negative-z axis, so to ensure the child is visible, set the z-coordinate of the child's position to a negative value.

scene.add( camera );
camera.add( child );
child.position.set( 0, 0, - 100 );

three.js r.94

Upvotes: 2

Related Questions