# Aligning a single triangle object's local origin (y axis) to the triangle's normal (non-backface side)

I have a billboard tree in Blender made up of a single triangle. I applied an Array and Curve modifier to it to instance itself on the curve. I collapsed the trees and separated them by loose parts. Now I have hundreds of trees whose local origins are aligned to the global axis, which is not what I need.

In Unity, I have a billboarding script that automatically aligns the trees to the face the camera. However, this script does not work if the tree's origins (or pivot points as they're called in Unity), are not aligned to the normal of the tree's front face (or back face, it doesn't really matter because I can just negate the script's LookAt function).

Does anyone know if there's a script available for this or would be willing to write a script that can move all the origins of selected objects to each of the objects' individual face normals?

Thanks.

In the mean time, I'm going to look into Python and see if I can figure something out, but I don't have a lot of time and have an intermediate level C# background.

Edit 01 - Added image of what I'm looking for. The yellow arrow shows the re-alignment I'm seeking:

Edit 02 - I cannot reply due to the 50+ comment restriction. @X-27, I followed your instructions, but was met with the following strange tilt after parenting and enabling Face Duplication (not to mention the duplicates stabbing the parents):

The only way to mitigate the tilting is to re-orientate the child tree into some weird angle in order to get the duplicated trees to be standing up, but their rotations are still messed up. Judging by your screenshots, you also have the same problem with the duplicated blue trees being angled in an awkward manner. This is not what I need.

Regardless, I appreciate your suggestion, but I no longer need this solution and do not have time to learn Python and the Blender API to make a script myself.

@yhoyo, I think you may have misunderstood my question. I already know of the Properties Shelf rotation and the script you posted simply zeroes out the Z rotation, which is not what I needed.

First off, you are way over complicating this. There is no need to use a script to correct the origin's rotation at all.

Starting with the tree with the array and curve modifier before it is applied (GCF green in images), instead of separating each tree along the curve, create a second tree (X-27 blue in images) and parent it to the tree with the modifiers.

Then set the the first tree's Duplication to Faces to add new trees with the location and rotation of each of the existing trees along the curve.

Then Make Duplicates Real by pressing Ctrl+Shift+A to make the second set of trees separate objects. Now all of the new trees have there own origins in the correct places.

If you want to, you can delete the curve and the first tree. Also, any tree you now select will also have the correct local rotation.

hi the easy way is change the rotation in properties panel

also you can select all the objects and run this script:

import bpy

obs = bpy.context.selected_objects

for ob in obs:
ob.rotation_euler[2] = 0


best