Rotate Around Local Y Axis

How does the unity rotate tool rotate around the local y axis? It seems that if I try to adjust localEulerAngles.y programmatically, we do not get the same effect. When rotating with the local rotate tool, x, y and z values are changed.

How can we rotate a transform around its local y axis?

http://docs.unity3d.com/Documentation/ScriptReference/Transform-rotation.html http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html

–

Say you wanted a Transform to Look (or point) towards a vector, while being constrained by the local y axis. How can that be achieved?

–

4 Answers

4

the space parameter is what you need:

transform.Rotate(0, yAmount, 0, Space.Self);

That would be my solution as well.

–

Thank you!

–

works perfect!

–

if i want to rotate the object along with mouse drag in complete 360' in clock and anti clock also

–
transform.RotateAround(transform.position, transform.up, Time.deltaTime * 90f);

transform.up is actually world axis up right?

–

transform.up would be the local axis Y positive axis (depending on whatever object the script is attached to). It would not actually be world axis up.

–

Typically, you need to turn something that already has a direction by some angle. Having the angle calculated from time is only useful for simple animations, nothing else.

–

Thank you! It was what I have been looking for.

–

Try this:

void Update()
{
    transformRotateAround(transform.position, TransformDirection(Vector3.up), Time.deltaTime * 90f);
}

private void Update()
{
transform.Rotate(0, 0, 10 * Time.deltaTime);
}

Thank you for your code! It works beautifully. Very simple and easy to understand!

–