- Home /
I have a gun model made up of multiple parts, attached to a rotating transform. Parts are transforming separately. (Images)
So first and foremost, the images, I feel like they accurately describe the issue.
The current hierarchy order: Head -> Gun -> GunParts
So I'm wondering if there is a way to fix this without making the model into a single part. I would much rather keep all the parts as separate children.
transform.localRotation=Quaternion.Lerp(transform.localRotation,Quaternion.Euler(ytargetRotation,xtargetRotation,0),Time.deltaTime*10/smoothing);
Global rotation makes no difference to the issue.
Answer by whebert · Apr 20, 2013 at 01:32 PM
Are you by chance using a scale other than (1,1,1) in any of the object's in your hierarchy? You can achieve this type of thing by using a non-uniform scale on a parent and rotating anything below it.
Ooh, this sounds promising.
I just tested with the root of the gun having a uniform scale. How would I set the child objects of the gun to uniform without scaling them out of proportion.
And is there anything else that needs to have a uniform scale? In terms of overall hierarchy, (obviously, everything below the Body is a localScale) it is as follows:
(1,1.5,1) Body (0.75,0.5,0.75) Head (1.33,1.33,1.33) Hand (0.25,0.25,0.25) Pistol
And then most of the objects in the pistol have non-uniform scales.
If you're going to be doing rotations of objects underneath any parent objects, you should use a uniform scale on those parents, otherwise you'll get odd looking child objects when rotated.
Thanks, rescaling the body to uniform scale fixed the issue. Glad someone knew what was going on, and now I know.
So this means that I cannot non-uniformly scale any parent without expecting issues like this to arise? Is there a way to circumvent it? Say I want to retain my bodies 1.5 y scale. (I'm probably going to make a body model and have uniform scale on it, but for future proof purposes, I would just like to know if there is a work around).
Thanks for the help so far!
There is no easy way to circumvent it that I know of. If you have a non-uniform scale on a parent and rotate a child, the affect of that non-uniform scale on the child will gradually switch from one axis to another as your rotate (in your example, the 1.5 scale is initially applied to the Pistol's Y axis, but gradually gets applied to the Pistol's Z axis, stretching it out).
This would be painful, but you could hypothetically counteract the non-uniform scale of the parent by applying a dynamically adjusting scale on the rotating child, keeping it's scale normalized. But it is so much easier to just keep your parents uniformly scaled.
Answer by Robble · Apr 20, 2013 at 01:07 AM
Do all the gun parts have a single transform as a parent?
Also which transform are you rotating?
No, my parts have different 'sub' parents. I'll try using a single parent. And now I am rotating a 'Head' object which the pistol is directly parented to.
Edit: Just tried a single parent for all the gun parts. No luck, same issue.
Answer by dendens2 · Apr 20, 2013 at 01:16 AM
Just add the parts to an empty gameObject. You can still modify them separately if you need to. At least if that is what you mean by, "I would much rather keep all the parts as separate children".
$$anonymous$$aybe it has something to do with the whole localRotation and not regular rotation. Just a guess.
$$anonymous$$aybe, I currently don't see why. I'll give it world rotation a try tomorrow morning. Hopefully someone will have encountered this issue previously and let me know what's going on! :D
Edit: Globally rotating made no difference to the issue.
Answer by DSebJ · Apr 20, 2013 at 07:31 AM
I don't think you should be using local rotation; just use rotation and you only need to apply the rotation to the root object.
I was pretty sure that the issue was not related to the localRotations, I gave global rotation a try anyway and sure enough the same issue is present.