transform.rotate/rotation?

Hi all!

I’ve got my character, and a trigger. The trigger triggers an animation and sets the position before and after the animation. However, the triggered animation is rotation sensitive and I could really do with getting the trigger to alter the rotation of the character too.

For the position I just used:

transform.position = Vector3(-113, 43, 462);

So I figured something similar would apply:

transform.rotation = Vector3(-0, 150, -0);

But it doesn’t like it! I checked the docs and it’s going on about eulers and quaternions and I just don’t understand it this late on a saturday night :wink:

Can anyone help?

Thanks!
Mike

Maybe transform.eulerAngles = Vector3(-0, 150, -0);?

Quaternions are not an easy concept to understand. Basically you need to abstract yourself from them. You need to know that a Quaternion is another way to represent a rotation, but unlike euler angles which are in 3 dimensional space, Quaterions are represented on 4 dimensional space (so it’s not possible to imagine a rotation on Quaternion - at least not for me!).

You can see in the following link how a rotation in euler angles is transformed into a Quaternion (q0, q1, q2 and q3 formulas)
Conversion between quaternions and Euler angles - Wikipedia.

If you had some math, you probably learned Complex Numbers, where square root of -1 is ‘i’. On Quaternions you have the same, but with ‘i’, ‘j’, and ‘k’ (i.e. like an extension of Complex Space).

Quaternions are important because they eliminate a rotation problem that euler angles have (if you rotate 90º around an axis, you loose a degree of freedom, so when you apply another rotation you will get some “odd” rotations).

Thanks for the info, guys! I’ll see what I can do.

Mike

Given how few people understand quaternions (I’ve always been good at math, and I’m still having a hard time wrapping my head around them), could there be some constants and/or more easily understood constructors for them?

For example, a constructor that is passed a single Vector3 could make it face that vector and assume that up = up. This would make easy statements like facing = Quaternion(Vector3.left);

In the meantime, could someone be so kind as to post the xyzw constructor values for some of the easy quaternions (like forward, backward, left, right)?

Did you take a look at LookRotation in the Quaternion documentation?

Your example above would then become facing = Quaternion.LookRotation(Vector3.left);

There’s also this handy one:

http://unity3d.com/Documentation/ScriptReference/Quaternion.Euler.html

-Jon

Thanks, I missed those!

Still… would have seen them if they were constructors. :wink:

The problem with constructors vs. static functions is that you can not tell from the constructor name what it will do with the inputs. Should a constructor that takes two Vector3s as parameters treat them as a direction and a world-up vector like Quaternion.LookRotation does or should it treat it as a from and to vector pair like Quaternion.FromToRotation does? The same applies to a constructor that takes a single Vector3. Should it treat is as Quaternion.Euler does or should it do the same as the single-parameter version of Quaternion.LookRotation?