- Home /
Strange movement artifacts when rotating children around parent object
Gif demonstrating the problem: http://i.imgur.com/8lHwFVD.gif
Object hierarchy: http://i.imgur.com/ZlpuFX4.jpg
Script attached to gun object: https://github.com/HPLoveshack/simple-animations/blob/master/AnimScript
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.
Don't have time to take a deep look, but non-uniform scaling of objects is typically the root of this kind of problem.
That may be it since the gun cubes are at a different scale than the player object. In fact, that sounds likely. Time for an experiment.
It was a scaling issue, turned out the parent object was scaled weirdly on the y axis somehow without actually scaling it's y size. $$anonymous$$aybe it inherited the scaling at some point while I was assembling stuff and I scaled something it was parented to.
If you convert to an answer I can mark it up.
Answer by TheCatProblem · Aug 06, 2014 at 06:45 PM
This might not be the problem in your case, but I once encountered similar behaviour when parenting an object with children to a moving object. In my case, some of the children developed offsets when the parent was rotated (this manifested as variable-width gaps appearing between the various child objects).
I was able to fix the problem by altering all the children such that their pivot points were coincident with the pivot point of the object containing them. In your case, this would mean that the pivot points of the Slide
, Receiver
, and Grip
objects would need to be located such that each of these objects is properly positioned when placed at (0, 0, 0) in the local coordinate system of the Gun
object.
I suspect this has something to do with floating point error. It seems that the position of a child object in the local coordinate system of a rotating object isn't preserved particularly well during rotation.
Turned out to be a scaling issue. I appreciate the effort put into your response though.
No worries; glad you were able to solve the problem.