Gif demonstrating the problem: http://i.imgur.com/8lHwFVD.gif
Object hierarchy: http://i.imgur.com/ZlpuFX4.jpg
Script attached to gun object: simple-animations/AnimScript at master · HPLoveshack/simple-animations · GitHub
Some context:
- The gun is made up of three cubes named slide, receiver, and grip.
- The player object has a fairly standard mouselook script that’s currently using quaternions. The problem was the same when I tried it with the standard unity mouselook script and when I converted my mouselook to euler angles.
- The problem disappears when I detach the gun from the parent and rotate the gun around its pivot point manually using the tool handles rather than rotating the parent object with my mouselook script.
- The scale and rotation as well as the x and z positions of the slide and the receiver are all exactly the same and were the same before parenting to the gun object. Only the Y position is different.
The trouble is visible in the gif. As I rotate the parent of the gun (player’s head) downward the slide on the gun retracts to a point higher than it should as I approach a 45 degree angle where the gap between slide and receiver is widest. As I continue downward to 90 degrees (straight down) the gap lessens until it is gone at 90 degrees. Rotating upward the problem is reversed, causing the slide to move downward and overlap with the receiver as I approach 45 degrees upward.
I don’t think the animation script is even relevant since without the animation the three cubes of the gun don’t maintain a static position relative to each other as I rotate upward or downward around the parent. The grip cube moves up and protrudes out of the bottom of the slide as I rotate downward and it doesn’t return to its proper position as I approach 90 degrees up or down. It seems to be a problem limited entirely to the Y axis.
There must be something wrong with how I’m parenting these together, pivot points, or how the parenting or pivots are interacting with mouselook, but I can’t seem to google up any answers. Maybe I’m just not able to phrase the problem accurately enough for a search to provide any useful results.
Surely others have run into this issue before though.