1
votes

As a continuation to: Point one object to face a distant object

I'm trying to get a mesh's surface to point to another object. I want a far away object to point to a close object, whenever the far object moves.

Here is a sample of what is happening: http://jsfiddle.net/UsVUv/

1) I create 2 mesh objects. 2) Since the far mesh is facing up, I rotate it so that it can be seen from the camera. -> farMesh.rotation = new THREE.Vector3(Math.PI/2, 0, 0); 3) When the far mesh is moved, I call the following to get it to keep looking at the near mesh. The face of the far mesh does not look at the near mesh, but the edge of its plane does. -> farMesh.lookAt(nearMesh.position); 4) I then try to rotate the mesh back so it faces the camera again, but that removes the rotation that the lookAt did. -> farMesh.rotation = new THREE.Vector3(Math.PI/2, 0, 0);

You can comment out the lines 1), 2), and 3) in the sample to see what is happening.

1

1 Answers

2
votes

Yes, the farMesh.lookAt() and farMesh.rotation are competing with each other.

What you need to do, instead, is rotate the farMesh plane geometry as soon as it is created with applyMatrix() like so:

    farMesh.geometry.applyMatrix( new THREE.Matrix4().makeRotationX( Math.PI / 2 ) );

So to summarize, applyMatrix() transforms the object's geometry, and lookAt() sets the object's rotation vector.

Here is an updated Fiddle: http://jsfiddle.net/UsVUv/1/