Setting the base of a transform.

Hi.
I have three orthnormalized vectors, let’s call them U,R and F.

I want to rotate an object such that its vector up right and forward vectors are aligned with U,R,F.

What I tried is simply

  transform.up = U;
  transform.right = R;
  transform.forward = F;

Obviously it didn’t work, or I wouldn’t be posting here :slight_smile:

I have an alternative solution but it’s using lot’s of trigonometry and squareroots. The problem here is that I need to do that as fast as possible as this code runs on hundreds of small objects on the iPhone.

So, any tips ?

Thank you very much.

Rotations in Unity are handled by quaternions. What you should do is set transform.rotation to whatever quaternion you want.

file:///Applications/Unity%20iPhone/Unity%20iPhone.app/Contents/Documentation/Documentation/ScriptReference/Quaternion.html

I bet that Quaternion.Euler would work out for you, but check out that page and get back to us.

Also, something that will help you out on the iPhone is caching game objects’ transforms in Transform variables. Let us know if you need help doing that.

Thanks for the fast reply.
I was hoping that I could do it without quaternions :slight_smile: Too bad.

Could you explain a bit more your trick about putting Transformation in a variable ?

Using quaternions in Unity really isn’t bad at all. By using Quaternion.Euler, you can work with easy-to-understand numbers, then store that in a Quaternion variable. You only deal with the quaternions indirectly if that’s what you prefer.

Here’s where I learned about caching components.

http://unity3d.com/support/resources/unite-presentations/performance-optimization

I can’t really think of a case where you’d want what “transform” refers to, to change, so I always do it. I declare a variable like

new Transform transform;

and then do

transform = GetComponent( typeof(Transform) ) as Transform;

You can do that sort of thing in Start, but I’ve been doing it using custom menu items that set up as much of my game as possible before it even runs. If you want to do that, the only way I know of is to declare a public variable, because public variables get serialized in the Editor. If you don’t want to see the variable on your game object, and you probably don’t, because it’s clutter, you can use HideInInspector.

Again, you’re new, so I have no idea what your programming knowledge is. When I came here in 2007, I had zero. Good luck and have fun with Unity! :smile: