- Home /
Preserving children when irregularly scaling parent
I'm trying to modify the scale of a player at runtime, but not uniformly, e.g., edit his height but not width or breadth. Now I want his firearm to remain unchanged, but this isn't happening.
To the player skeleton I added an empty "palm" gameobject to set the base firearm position, and the firearm model has an empty gameobject parent as a base with a uniform scale of 1. At runtime, the firearm base is parented to the palm object.
I am seeing two issues. One, the firearm does not appear to be preserving its scale when I set its parent, and two, more importantly, the firearm disintegrates and its different parts move in different ways.
Is there a way to solve this?
Answer by Owen-Reynolds · Sep 05, 2014 at 02:05 PM
Use hand-coded fake parenting. Keep just an empty on the hand, where the gun should be, to let Unity track it for you. Don't child the gun, to avoid inheriting a crazy scale. Instead, in Update:
gun.position = gunEmpty.position;
gun.rotation = gunEmpty.rotation;
The problem with real parenting and non-uniform scale+rotation isn't that it's buggy, but that it works properly. The gun distorted along those odd axis is the real math (scaling the player on world-Y scales the gun on world-Y.)
Then, if you want the gun to scale with the player, you can hand-scale the unchilded gun (which will use it's local axises, and look good.)
Thank you for your suggestion. Actually, I did try that, seeing it on another post about the topic, but using this method does not seem to update fast enough, as the gun lags a little. Do you have an idea to solve that?
Partly lies in knowing the exact sequence in which unity runs things. If the arms are set by an animation, the place to add "now that animation is finished" is in LateUpdate().