Align objects rotation to vector via python

Hi there!

Im trying to create a script that aligns objects to the normal of a face (this will be part of a modal opperator). I get a ray cast hit location and the normal of a corresponding face which works fine. So the normal vector is correct.

So the question is: how to align the rotation of an object to a given vector (in this case the normal vector of a face)?

object.rotation_euler = Euler(normalVector)

…gives me wrong results.

What am Im doing wrong?

Thanks in advance!

Hey !
I’ve done this in another life, sorry I can’t remember exactly …
Maybe looking on stackexange you can find some more informations :

Bear in mind that even if it will orient the object to that vector, you’ll be still missing the rotation around the vector. But you can look on that latter if needed …

The issue you’re having is that Euler takes tree angles in radian rather than a direction based on location.
Good luck !

Thanks for your reply!

Unfortunately it only works for surfaces that are not “curved”?! Which makes absolutly no sense as the normal direction is correct.

Have a look at the screenshot:

Go it. I needed to apply the objects matrix to the normal to get a world vector. The target mesh had rotation on it. Thanks anyway! :slight_smile: