user2205268
user2205268

Reputation: 3

Three.js Rotate objects inside of moving Object3D to always face the camera

I'm somewhat new to Threejs was just wondering how to make moving mesh always face the camera in a scene. I have 100 meshes inside of a container Object3D, and am rotating this container on the x and y axis. Is there any way to force the meshes inside of the container to always face the camera?

Here is some sample code, I've also set up a jsFiddle at http://jsfiddle.net/nickelWeb/rZtJX/4/

for(var k = 0; k<numMeshes; k++){
     meshes[k].lookAt( camera.position );   
}

I have tried just using the .lookAt() method but it doesn't seem to be working. I know there has to a way to do this i'm just not sure where to look. Any help would be appreciated. Thanks!

Upvotes: 0

Views: 3529

Answers (1)

WestLangley
WestLangley

Reputation: 104833

Object.lookAt() will not work correctly if the object has a parent that is rotated.

The absolute easiest solution to your problem is to hold the parent object fixed and rotate the camera around the object instead.

That way, Object.lookAt() will work as expected.

Updated fiddle: http://jsfiddle.net/rZtJX/5/

three.js r.57

Upvotes: 2

Related Questions