3
\$\begingroup\$

In the scene I have a capsule with a camera parented and a looking script so when I look down or up the weapon slightly moves forward and then moves back when I look straight forward.

weapon when I look up or down-

enter image description here

and heres how it looks normally when I look straight forward-

enter image description here

Anyone knows how I can fix that?

EDIT: Here's how it looks in scene view

enter image description here

\$\endgroup\$
  • \$\begingroup\$ The movement of gun must be in code or animation , you need to comment out that particular block. \$\endgroup\$ – Hash Buoy Aug 23 '15 at 8:28
  • \$\begingroup\$ The gun is parented to the camera so as the camera moves and rotates the gun does too. \$\endgroup\$ – Vadim Tatarnikov Aug 23 '15 at 10:48
  • \$\begingroup\$ so i don't quite understand what you mean \$\endgroup\$ – Vadim Tatarnikov Aug 23 '15 at 13:53
  • \$\begingroup\$ Can you share the screen shot of hierarchy for the gun and cam?? My second guess is the way the cam moves , due to which it might be causing the back and forth movement of the gun. \$\endgroup\$ – Hash Buoy Aug 23 '15 at 14:22
  • \$\begingroup\$ Ok I edited the question \$\endgroup\$ – Vadim Tatarnikov Aug 23 '15 at 14:35
1
\$\begingroup\$

This is a strange behaviour in Unity's scale inheritance system. If the parent has a non-uniform scale, when you rotate the child, they deform/stretch like a rubber band.

Try adding an empty child GameObject to Player GameObject and parent the Camera GameObject to empty one, and put the rotation script on Camera. This makes parent of the Camera a uniform-scaled transform, so your rotations won't alter childs' scales.

Note: Make sure the empty GameObject has a uniform scale (ie, 1-1-1).

| improve this answer | |
\$\endgroup\$
-1
\$\begingroup\$

Parent the gun to the player not the camera. The camera movement is changing the transform of the gun. The capsule for the player still tips forward and backwards so parenting it to the player will alleviate the issue. Otherwise you can code a fixed transform that only allows for verticle and horizontal transform change instead of a forward transform change to follow the camera if you don't want to change what it's parented to.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.