Orbitcontrol track moving object

Hi every one,

I’m working on a stelar system map, for an upcoming Game
but I have some trouble

here is my prototype map : https://global-chaos.fr/game/map

when you click on a planet (the greens hexasphere), the Orbitcontrol target is change for the planet,
but I would like to get the camera position change to follow the object, by reading this https://stackoverflow.com/questions/24855708/how-can-i-apply-trackballcontrols-to-a-moving-target

I have added a function to orbit control to follow the target :

this.goTo = function( vector ) {

but I’m doing something wrong with camera calculation, the function is keeping the camera zooming on the Target (the planet), and not allowing me to use the Orbitcontrol

I would like that the camera follow the target, without zooming constantly on it, and following it’s rotation

I think the problem with your use case is that you produce a conflict situation that OrbitControls can’t handle without modifications. Normally, OrbitControls is responsible for changing the transformation for the given object (the camera). If you now want an additional transformation e.g. so the camera moves along another object, the result of OrbitControls will overwrite your custom modifications or vice versa.

One way to solve this problem is to disable panning and zooming of OrbitControls and position the camera by yourself. In this way, you don’t have to modify OrbitControls. The following simple fiddle illustrates this approach.


1 Like