- Home /
How to change the pivot point of a mesh in script?
Hi everyone who reads this! I have a gun mesh that is supposed to rotate when you move your mouse and stuff. It all works find and dandy, except the pivot point is were I would want it to rotate. Here's the section of my script that does the rotating. transform.position = cameraObject.transform.position + (Quaternion.Euler(0,targetYRotation,0) Vector3(holdSide racioHipHold, holdHeight * racioHipHold, holdZ)); targetXRotation = Mathf.SmoothDamp(targetXRotation, cameraObject.GetComponent(MouseLookScript).xRotation, targetXRotationV, rotateSpeed); targetYRotation = Mathf.SmoothDamp(targetYRotation, cameraObject.GetComponent(MouseLookScript).yRotation, targetYRotationV, rotateSpeed);
I'm need it to rotate farther back on my gun. How would I go about doing this? I'm new to unity so this might be a noob question, but i hope somebody can help :)
Answer by SinisterRainbow · Jun 14, 2013 at 05:11 AM
can you please use the code formatting button in the future, it's a headache enough to read other people's code even when nicely formatted :).
The best thing to do is set the pivot in your modelling program ahead of time. If you are not using it for rotation in any other way, this is the easiest way. There are other answers here that have solutions to this but none of them are very elegant unfortunately. That being said, if you know the local position of the pivot point you want (by checking in your modelling program for example), you can rotate around that local point. I can't remember exactly the unity method But I believe it is something like "RotateAround(...)" which you can easily look-up.
Your answer
Follow this Question
Related Questions
Rotation of object 0 Answers
A node in a childnode? 1 Answer
How to rotate instantated prefab without rotating it's local directions by javascript? 1 Answer
I am having an issue with the rotation of a child 1 Answer
Disabling the Z axis? 1 Answer