Shien
Shien

Reputation: 515

Check if object is looking at position

I'm trying to check if an object (this.target) is looking at a specific position (newPosition). What I have right now is the following:

new THREE.Matrix4().lookAt( newPosition, this.target.position, this.target.up ) == this.target.matrix

But for some reason, this won't work. How are you meant to check if an Object3D is looking at a specific position?

Upvotes: 0

Views: 385

Answers (1)

Flux
Flux

Reputation: 666

That won't work because the matrix for your target is not in the same place, and can be scaled differently and all sorts of stuff.

A better technique is to raycast from your eye object, and see if it hits the target object.

http://threejs.org/examples/#webgl_geometry_terrain_raycast

var raycaster = new THREE.Raycaster();

raycaster.setFromCamera( mouse, camera );

// See if the ray from the camera into the world hits one of our meshes
var intersects = raycaster.intersectObject( mesh );

Upvotes: 1

Related Questions