Reputation: 91
I have an object that I want to move directly towards the camera when given the proper input.
I've taken a look at Object3d.translateOnAxis(axis, distance)
, but I can't seem to set the axis
(the object's local axis) to always face the camera. This may be because the object is also rotating.
Since I have multiple objects on the scene, I need the objects to move towards the camera.
Upvotes: 3
Views: 4077
Reputation: 633
For me what's working to move the object 5 meters is:
var dir = new THREE.Vector3();
dir.subVectors(camera.position, object.getWorldPosition(dir)).normalize();
object.translateOnAxis(dir, 5);
Upvotes: 0
Reputation: 91
I figured out how to get it working. Say I want object
to travel towards the point (0, 0, 25) in world coordinates. object.translateOnAxis(object.worldToLocal(new THREE.Vector3(0,0,25)),50);
will make the object travel 50 units towards the point (0, 0, 25) from its current location.
Upvotes: 4