How to rotate a game object around its local y-axis?

I just need to rotate a game object and its children based around the parent’s local y axis… meaning the rotation does not move the object anywhere besides its local rotation.

I have tried many many scripts and tutorials, but the object always moves around an axis out in space.

I am a beginner to Unity so a full script would be very very helpful. Thank you!

transform.Rotate( new Vector3(0, 5, 0), Space.Self );

I was Incorrect Have Deleted this original statement,…

new answer is below aswell in reply.

//

Hey thanks meat5000 i used Ilspy to open the Source code and i found the issue at large is to do with a lack of been able rotate from space.self . Local Euler is working correctly.

Cheers bunny. u r correct but at the time i posted this i was rather sure it had to be a mistake, untill meat5000 meantion ILSpy and i was able to look at the source code and figure it all out.

In the human mind LocEuler does somthing else from what it actually does in reality this is due to the rotations being a “difference from the parent axis” this causes in most cases people to try to use LocEuler thinking its going to rotate the object itself, but in reality it rotates it relative to parent, this causes the axis to not do what is usually intended aswell as there been gimblelock which kinda sucks big time.

You are correct there is no fault in unitys code but rather a lack of the correct code to rotate an object based off its own axis not localparent or world.

the only code which does this is Transform.Rotate () but this lacks the ability to clamp the angles as far as i know im still trying to figure this one out.

i was able to modify the transform.rotate code tho to produce a clamp-able space.self rotating code that alwasy rotates the correct axis with a angle clamp.

the clamp functions but needs a little more and i worked all night on it so im tired right now :slight_smile:

here is modified code below Good luck :slight_smile:

//Starts Modified code

public Quaternion RotInput = new Quaternion();

public Quaternion TempRotate = new Quaternion();
public Vector3 TempRotInput = new Vector3();
public Vector3 TempClampL = new Vector3();

Void update()

{

                              //Left Rotation Begins

                             RotInput = Quaternion.Euler(CameraRotate.x,CameraRotate.y,CameraRotate.z);

                             TempRotate = LeftUpperArm.transform.localRotation ;

                             TempRotate *= RotInput ;

                             TempRotInput = TempRotate.eulerAngles ;
                           
                             TempClampL = new Vector3 ((Mathf.Clamp((TempRotInput.x),LUpperarmXmin,LUpperarmXmax)),(Mathf.Clamp((TempRotInput.y),LUpperarmYmin,LUpperarmYmax)),(Mathf.Clamp((TempRotInput.z),LUpperarmZmin,LUpperarmZmax)));

                             LeftUpperArm.transform.localRotation = Quaternion.Euler (TempClampL) ;

                             //Left Rotation Ends

//

Sincerely Exvalid