Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Three js - Have object move towards camera

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.

like image 381
user3778411 Avatar asked May 06 '26 20:05

user3778411


1 Answers

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.

like image 138
user3778411 Avatar answered May 09 '26 09:05

user3778411