Hello all, i'm trying to rotate some vertices in a mesh about a 3D cursor while preserving the up vector.

If I were in Unity I'd use the "LookAt()" function by specifying what I want the object to look at and also specifying the 'worldUp' vector to make the rotation robust for all rotations:

---

from http://docs.unity3d.com/Documentation/S ... ookAt.html

"function LookAt (worldPosition : Vector3, worldUp : Vector3 = Vector3.up) :

Rotates the transform so the forward vector points at worldPosition. Then it rotates the transform to point its up direction vector in the direction hinted at by the worldUp vector. If you leave out the worldUp parameter, the function will use the world y axis. worldUp is only a hint vector. The up vector of the rotation will only match the worldUp vector if the forward direction is perpendicular to worldUp. "

---

What would be the closest Blender equivalent to doing "LookAt" rotation?

Thanks for any help! Lost on this one!!

Dan,

## Closest equivalent to Unity's "LookAt" rotation in

**Moderators:** jesterKing, stiv

isn't that a rotation about the up-axis? you can simply calculate the angle difference between the target vector (looks at target) and the forward vector, then rotate around z-axis by that angle. If the rotation axis isn't at the same location as the up-axis, then do as follows:

center needs to be a 4x4 translation matrix. You can use the location of the object, the median point, the center of mass or whatever you want - depends on what you desire.

You can construct a translation matrix like

Matrix.Translation(vector)

and a rotation matrix like

Matrix.Rotation(radians(num_of_degrees), 4, axis)

axis can either be a char ('X', 'Y' or 'Z') or a vector.

Code: Select all

```
mat = center * rotation_mat * center.inverted()
me.transform(mat)
me.update()
```

You can construct a translation matrix like

Matrix.Translation(vector)

and a rotation matrix like

Matrix.Rotation(radians(num_of_degrees), 4, axis)

axis can either be a char ('X', 'Y' or 'Z') or a vector.

I'm sitting, waiting, wishing, building Blender in superstition...