- Home /
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?
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?
Answer by ScroodgeM · Jul 23, 2012 at 06:21 PM
transform.RotateAround(transform.position, transform.up, Time.deltaTime * 90f);
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.
Just wanted to say that this is useless if you need to set absolute rotation and not incremental, which is a rare occurrence as i can see.
If you need to set absolute rotation, transform.rotation = originalRotation * Quaternion.Euler(desiredChangeInRotationX, desiredChangeInRotationY, desiredChangeInRotationZ);
Answer by KelNishi · Jun 25, 2013 at 09:19 AM
the space parameter is what you need:
transform.Rotate(0, yAmount, 0, Space.Self);
if i want to rotate the object along with mouse drag in complete 360' in clock and anti clock also
Answer by Shgoedt · Jun 03, 2013 at 09:36 AM
Try this:
void Update()
{
transformRotateAround(transform.position, TransformDirection(Vector3.up), Time.deltaTime * 90f);
}
Answer by jckhunt4 · Jan 07, 2019 at 11:34 AM
private void Update() { transform.Rotate(0, 0, 10 * Time.deltaTime); }
Thank you for your code! It works beautifully. Very simple and easy to understand!
Your answer
Follow this Question
Related Questions
use world axis when using transform.rotate 3 Answers
use world axis when using transform.rotate 0 Answers
Rotation in 8 way direction 2 Answers
Lock the y axis (on an object that's not a rigid body) c# 0 Answers
Is it possible to keep an object upright inside another game object that is spinning or rolling 1 Answer