alignAxisToVect problem

hello,
i make a script which allow me to add new planes. Each plane tracks the camera. You can move the camera with
keyboard’s arrows. So my problem is that the plane doesn’t track the camera in 3D. Some of their axis are not aligned.
i join a .blend file. try the following :

  • add some planes with spacekey
  • control the camera with Arrow keys
  • go through the planes
  • turn around and you will see that the planes are not correctly aligned.

how can i track correctly the camera in 3D ?
thank you !

trackCamIn3D.blend (524 KB)

Go to object properties, near the bottom is relations extra, set the tracking axis to z,

It all tracks correctly for me. The only issue that I see is that the planes don’t stay vertical, if that’s what you wanted. You may have to do another align if you want to do that.

Go to object properties, near the bottom is relations extra, set the tracking axis to z,

you are talking about up axis or axis ? +z or -z ?

It all tracks correctly for me. The only issue that I see is that the planes don’t stay vertical, if that’s what you wanted. You may have to do another align if you want to do that.

yes the problem is that planes don’t stay vertical. how can i do another align ? I try to add a alignAxisToVect function for each axes but
strange things occurs, it seems to generate a conflict between the differents alignAxisToVect call…

Good point, two axistovect will conflict.

One way to deal with this is to make sure that the local Y rotation is zero.
Put these in at line 28:

            ori = objList[i].localOrientation.to_euler()
            ori.y = 0
            objList[i].localOrientation = ori

yes it works !
but can you explain me why the planes didn’t stay vertical ? why did the Y location of each plane change ?

thank you !

The y rotation sometimes changes because alignAxisToVect doesn’t specifically try to make the alignment without changing it. It doesn’t care about that, it only cares about the specified axis pointing to the direction you ordered.

I’ve personally used two alignAxisToVect() right after each other in the same function and it hasn’t conflicted in my case. First align to track to camera and next align to align Z axis to world Z axis. But orientation fix also works and is perhaps more to-the-point method, I’ve shifted to using it.

When you need to align individual faces only the best approach is to use billboard face orientation mode for if you want Z axis to stay straight.