Home > OS >  Unity rotating an object on the Local Space
Unity rotating an object on the Local Space

Time:01-11

I made a video for easier understanding. https://www.youtube.com/watch?v=Y6oHiCNVQv8

When I change the local rotation of an object, the axes change and I can't find the right direction.

desiredAngle ----> (90,0,0) (0,90,0) (0,0,90)

private void MainRotate(Vector3 desiredAngle)
    {        
        mainObject.transform.DORotate(desiredAngle, 1, RotateMode.LocalAxisAdd);      
    }

CodePudding user response:

Just use RotateMode.WorldAxisAdd

mainObject.transform.DORotate(desiredAngle, 1, RotateMode.WorldAxisAdd);

CodePudding user response:

You are clearly confusing local and global space.

You say you want to rotate in local space but from what you are saying it's obvious you want to rotate in global space.

In any case if after the first rotation you still expect the second rotation (the one around the Y axis) to take place around the global vertical axis then it's clear you should rotate around the global Y axis.

if you want to see how local axis behaves you should rotate the GUI axes together with the object.

I see you are using DoTween. Nothing wrong with that however I would suggest to understand how transform.rotation and transform.localRotation work, first.

  •  Tags:  
  • Related