- Home /
Making object a child causes distortion/skewing
I'm trying to make an arrow projectile, so when the arrow hits a collider, the collider becomes its parent (so that the arrow will move with the collider, and it will look like it's embedded in it). The only problem is that sometimes when the arrow is made a child it gets distorted and stretches/skews in very strange ways.
Is there anything that I can do about this? I know that sometimes objects behave strangely when made children, but not how to fix/avoid it.
P.S. the arrow is a rigidbody but I make it kinematic on collision, and the target is currently a cube
Thank you in advance to anyone who answers!
Answer by Miriam · Jul 07, 2010 at 05:56 PM
Hi,
I'm having similar problems. (my post: http://answers.unity3d.com/questions/14594/geometry-distortion-on-child-objects)
The standard cause for this problem (which didn't help me but may help you) seems to be a combination of:
- non uniform scaling on your parent object.
- AND arbitrary rotation on your child object.
Hope that helps
Edit: Having uniform scaling on my child objects (not just parent ones) seems to be helping a bit with the skewing problem.
Also, you could try set up a script like this on the arrow object:
var followThisObject : GameObject;
function onHitObject (objectHit : GameObject){ followThisObject = objectHit; }
function Update(){ if (followThisObject != null){ transform.position = followThisObject.transform.position; transform.rotation = followThisObject.transform.rotation; } }
Then when the arrow hits an object send an "onHitObject" message to the arrow.
You might also need to store variables with the relative position & rotation of the arrow to the hit object and add those each update as well.
Good luck!
Thanks. Unfortunately i'm firing arrows in a full scene so both of those are givens (I was hoping there was something else which could be causing it).
If you can't figure out a proper solution you could always fake it - ie ins$$anonymous$$d of parenting the arrow put a script on the arrow that makes it follow the cube.
Well the issue is that the arrow can stick into anything, including hinged objects and such, in my scene.
Answer by Andy.... · May 30, 2014 at 03:04 PM
There is another easier way to solve it ( at least, worked for me)
Example:
Vector3 originalScale = transform.localScale;
// Do parenting stuff...
transform.localScale = originalScale;
thanks. this solution did work for me!
ePrefabs.Add(Instantiate(Resources.Load(tempString, typeof(GameObject))) as GameObject);
var originalScale : Vector3 = ePrefabs[i].transform.localScale;
ePrefabs[i].transform.parent = Platform.transform;
ePrefabs[i].transform.localScale = originalScale;
ePrefabs[i].transform.localPosition = pos;
Answer by Noise crime · Jul 10, 2010 at 10:52 AM
If its a case of non-uniform scaling you could use an empty game object as the parent to the collider. So instead of moving the collider, you now move the parent. You still check collisions through the collider, but when attaching the arrow, you attach it to the empty game object instead.
This means your collider can have non-uniform scaling, but your arrow wont inherit it as its no longer parented directly to it.
Well the collider can be anything in the scene, so I would prefer not to put empty gameobjects on everything with a collider.
No thats pretty much the idea, but if its going to stick to everything then I can understand not wanting to parent empty game objects.
Answer by George-Dolbier · Apr 21, 2018 at 02:37 PM
Just confirmed this is still a bug in Unity 2017.3.1f1 Not saving and restoring localScale of a child object of an object with skewed scale, causes really bizarre behaviour. It looks like the child object's scale is tweaked by the inverse of the parent's scale squeue. My parent object scale was skewed in only one axis and all my children where stretched along the same axis. but saving the local scale and restoring it does not exactly fix the problem. Local Scale shows up in the editor as the original scale of the object, but the objects are now all the same absolute dimension (meaning parent and child are the same width, even though the child prefabs where much wider).
This is not a bug but the simple result of a chained linear transformation. When you have a non uniform scale on the parent and a rotated child there is absolutely no way to preserve the childs shape as the scaling will not be aligned with the local axes. Therefore you can not set any reasonable scale on the child which could undo the transformations. That's also the reason why there is no "world space" scale but only a localScale and a lossyScale. The lossyScale tries to approximate the world space scale, but with a non uniform scaling and rotation it's impossible to restore the original scale of the object. It would require you to undo all transformations in reverse which is not possible with a single matrix. You may want to have a look at this video which explains this problem a little bit in detail.
If you have a parent-child relationship you just don't want to have a non uniform scaling on the parent. Just create an empty gameobject which acts as parent and give it a scale of (1,1,1). Then just add your original "parent" as well as the child both as child to the empty gameobject.
Non uniform scaling also has an impact on performance. Objects with non uniform scaling can't be batched. Also Unity can actually detect a uniform scaling and simplify the transformation.
ps: Non-uniform scaling also may give you trouble with surface normals, especially when the normal is not aligned with the local axes.
Your answer
![](https://koobas.hobune.stream/wayback/20220613064049im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Connecting Multiple Rigidbodies with Collision 0 Answers
Child Gameobjects are not fixed to the parent when using physics 0 Answers
Add sub object to Rigidbody 1 Answer
Empty Object as Parent without Rigidbody? 0 Answers
Touch the same GUITexture button to Pick Up and Drop a Rigidbody Game Object 0 Answers