- Home /
Gun is stretched when camera move in FPS game
I am working on an FPS game, and I attached the gun to the camera. But I found that when the player looks up or down, the gun will be stretched.
this is how the gun looks normally:
And this is how it looks after the stretching
Any suggestions? Thanks.
Strange behavior. Does the camera's scale change during play?
you'll have to show code seems pretty clear your changing the scale or rotating oddly etc.
Answer by Space_Cowboy27 · Aug 17, 2020 at 08:35 PM
I guess, it's really late, but if someone will stumble on this question, i learned it today: your parent object (rectangle in this case, as a player) should have the same scaling on every axes, so your player game object should have, for example, x: 1, y: 1, z: 1 scale.
Answer by FlaSh-G · Aug 17, 2020 at 05:49 PM
This is what happens when you have scaling in a hierarchy of GameObjects.
Imagine how hierarchies work. For example, think of a tank. The base is moving and rotating, and the turret moves and rotates with it. In addition, the turret can rotate (and, if you wish to, move) relative to the base. Now, when you move the turret to the side, and rotate the base, the turret will rotate around the base, rather than rotating around itself. Or, in other words, when you move the turret to the east, then rotate the base, the turret will not be in the east anymore. This is because the rotation applies to the relative position of the child object. And the same applies to scaling.
When you scale an object on an axis, all its children will stretch on that axis as well. The size of all objects in the hierarchy is still proportional. If the tank's turret was half as wide as the tank's base, it will still be half as wide after you scale the entire tank. Now, if you were to rotate the turret by some amount, the turret will not keep the same relative scale as before. If the turret points north, and you scale the tank to be wider west to east, the turret will have a larger width. But if the turret points east, the turret will become longer instead. So rotating a child object of a non-uniformly scaled parent will shift the child object from being wide to being long. And inbetween those 90° angles, the child object will be skewed, as is your gun.
Long story short, never (non-uniformly, but actually: generally) scale an object that has children, and save yourself a lot of hassle.
Your answer
Follow this Question
Related Questions
FPS - Gun Delay while Rotating 0 Answers
Weapon pick up 3 Answers
Basic First Person Shooter Weapon Setup!?!?! 1 Answer
FPS recoil, lerp fighting 0 Answers
Non-player-held weapons rendering through environment 1 Answer