Well I’ve run into a wall with this one, I thought I was being extra simple with my setup but it looks like I’ve run into an odd problem I haven’t encountered before but others have except the solutions they suggest I either don’t 100% understand or they haven’t worked for me.
I have my player, a main camera and an imported model all attached to each other, the player movement works absolutely fine and the camera is fine by itself and the movement is as you’d expect for an FPS but the model no matter which way I rotate it even when I rotate it in the editor while it’s a child of the camera stretches the way it’s shown in the old post I found.
Does anyone have any ideas as to why this is happening in this particular project? I encounter none of this behaviour in my other project that I tested this out in. What’s weird is this seems to happen even in the editor so it’s doesn’t seem to be anything to do with my FPS controller script and it’s to do with the camera, oh and just to add this also happens in play mode as well as the editor.
I can get the gun not to stretch when it’s parented to the player but this isn’t exactly ideal as it only copies horizontal movement.
Huh, well this is strange, when I make a new camera it seems to default to 2.791555, 1.24481, 15.39275, could it be that there’s something the default settings that’s messing with new cameras? I’m wondering because I updated Unity fairly recently to 2018.3.
My mistake, a non-uniform scale on the camera wouldn’t affect the gun as it is the camera that is being rotated. Make sure that all of the parents of the camera itself have uniform scaling (x, y, and z are the same).
Here’s a demonstration what’s happening to your gun:
Both of these objects are default unity cubes. The grey cube has a non uniform scale, and the white cube is simply parented to it and rotated slightly. This is an effect of how matrix transformations interact with rotation and scale, and there’s nothing you can do about it except avoid situations where parents of rotated objects have non-uniform scale.
The same thing is happening to the camera, but you don’t see the effects since cameras don’t have any geometry that is affected by scaling.
This is really confusing and frustrating, I may try making a whole new project and see if that fixes things. If this is the case why have I only run into this problem now? I checked out the documentation and it looks like I’ve semi-fixed things now and prevented the stretching, however it’s really unhelpful I have to keep everything uniform like this when I haven’t had to do it before.
My basic setup is really simple, I’ve got a scaled cube as a player, a camera and a cylinder for a gun, if I set the player and the camera to 1, 1, 1 then everything is fine, but of course this means now I can’t put my models in? Am I going to have to make an empty and camera first before I do anything else just to make this all work?
I’m just annoyed I’ve only encountered this now so I’m going to have to think around it when I didn’t have to before and have never had problems, by the way for those reading the thread this is the documentation I looked up which explains it in detail.
Pretty simply, you’ve probably just never worked with non-uniform transforms interacting with rotations before. It’s not that common of a use-case.
Of course not. It just requires a slightly different method of structuring your objects, which coincidentally also makes your life easier in other ways as well.
Yes. This is the same way that I and many others approach constructing something like a player controller. An empty at the root with a camera as a child, and a separate child object to contain any player graphics. This makes the actual functionality of the player a lot less dependent on the graphics of the player, and makes things like swapping out the player model trivial.
For what it’s worth, I’ve never had to “think around” non-uniform rotations. It’s rare to run into it, and it’s trivial to avoid.
As I said in my last post, this is an entirely expected and accounted for side effect of how matrix multiplication works. We use matrices in 3d rendering because they’re very fast and very parallelizeable, and they allow us to be able to perform the millions and millions of calculations per second necessary in order to render complex three dimensional scenes. Many 3D program with a hierarchical structure will have this limitation (as a side note, the Unreal Engine seems to use a different method for concatenating transform hierarchies, and doesn’t display the same distorting behaviour).
Thanks for all the help, seriously, that was annoying me like mad lol yes I think it’s just because I haven’t run into this problem before. What I did to fix this was use an empty first and then making my camera a child of that, after this everything seemed to behave normally.
Oooooooo -_- lol I’ll just need to double check now that everything works with the FPS controller but it should all be fine, guess it’s just one of those annoying game engine based quirks I have to get used to like pivots.
I’m stumbling on this 3 years later as well, my player was a cube that I changed the scale of and I was also experiencing this. Changing the cameras parent to a scale of 1,1,1 did in fact solve this issue thanks Madgvox!
I made a object called PlayerHolder and placed my Player object under it.
Now I set the player’s scale to 1-1-1. But i set the scale of the PlayerHolder to the scale of my Player before placing it under it’s parent.
So now my Player holder is 1.5 - 2.02 - 1.5 but my Player is only 1 - 1 - 1.