Does anyone know why this is happening?
This stretching occurs as the result of a parent Transform's non-uniform scale being applied to a child Transform. This becomes especially visible during rotation, when that 3-axis scale attempts to apply itself to a child Transform at any, but especially at any non-90-degree rotations.
A simple solution to this is to ensure that a GameObject’s parent Transform has a uniform scale
Vector3.one * scale (for example, by putting both parent and child objects into a separate, unscaled container instead).
Create two cubes, then drag one onto the other in the Hierarchy to make it the child object.
Scale up the parent object on a single axis. The child will scale along with it. Note at this time that the child’s scale is still (1, 1, 1).
Rotate the child. It will deform heavily during the rotation, since it’s being stretched along a fixed axis by its parent.
To deal with this: Create an Empty GameObject. This will act as the new “parent” to the child instead. When you drag it onto the Parent Cube to make it a child, Unity will automatically calculate the inverse scale to ensure that its scale becomes (1, 1, 1), relative to its parents. Additionally, ensure that it has no rotation relative to the Parent Cube (otherwise, you will see distortion again).
Rotate the Child Cube again. This time, it will behave as you intend for it to.
All objects have a pivot (origin) around which they scale and rotate. If this is not in the point you want it to rotate around, you’ll get this kind of behaviour.
This is set in the modelling software rather than unity. If you’re using Blender, select a vertex on the grip in edit mode > shift S cursor to selection > object mode > object > set origin > origin to 3D cursor.
@tuinal, thank you for your time, but that didn’t seem to help the problem. I followed your steps word by word, and it just didn’t seem to work.
Okay, so first we need to know how you’ve created your gun. Have you modelled the gun in a separate application such as Blender or 3DS Max, or have you just made it from cylinders using Unity by itself? Judging by the names of the objects, it looks like you’ve just cobbled together some cylinders in Unity, which is fine but this makes things a little more complex…
So, if you’re going to make your gun in Unity, I’d suggest starting with an empty GameObject which you can name “Gun”, and then put a couple of cylinders inside of there to represent the grip and barrel. Now the important thing is that you leave the position, rotation, and scale of your “Gun” object at (0,0,0), (0,0,0) and (1,1,1) - this is going to save you a bunch of headaches later on.
With this in mind, adjust the position, rotation, and scale of your cylinders to model your gun - you shouldn’t need to mess with the transform of “Gun” to do this. One thing to remember is that you need to position your grip and barrel so that they lie at a suitable point in relation to the origin (0,0,0), as the origin is the point around which your gun will rotate.
Hopefully this will help a little. Just give us a shout if you need any more help (I don’t know how new to games development you are, but remember we all have to start somewhere)!