Rotating Locally?

So I’m using this script to rotate one of my objects.

var roatateSpeed = 20;

function Update () {
  transform.eulerAngles.y += roatateSpeed * Time.deltaTime;
}

The problem is that it rotates the object on the object on the Global Axis, which is not the effect I want.

Any ideas on how to rotate it locally?

Thanks

Disregard that last post. This somewhat works, but now they rotate for a while and then stop.

Help?

There’s no way to say what the problem is, because we don’t know what you’re doing exactly or what your code looks like.

Ummmmm… I put my cod in the first post…

No, you posted your original code in your first post :slight_smile:

Your subsequent posts would seem to indicate that the code’s been changed since then. If not, perhaps you could clarify that (just so we know what we should be looking at).

var roatateSpeed = 20;

function Update () {
  transform.localEulerAngles.y += roatateSpeed * Time.deltaTime;
}

I’m not sure how Unity handles Euler angles internally off the top of my head (it might say in the docs somewhere). I assume it behaves sensibly as far as the ranges of the angles are concerned when an individual angle is modified, but without checking I can’t say that for sure.

However, you shouldn’t need to use Euler angles at all for this. Instead, you can just write (untested):

var rotateSpeed = 20;

function Update()
{
    transform.Rotate(Vector3.up * rotateSpeed * Time.deltaTime);
}

As the docs say about eulerAngles: “Only use this variable to read and set the angles to absolute values. Don’t increment them, as it will fail when the angle exceeds 360 degrees. Use Transform.Rotate instead.” Also: “Do not set one of the eulerAngles axis separately (eg. eulerAngles.x = 10; ) since this will lead to drift and undesired rotations. When setting them to a new value set them all at once as shown above.”

–Eric