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!

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!

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.

There is another easier way to solve it ( at least, worked for me)

Example:

Vector3 originalScale = transform.localScale;

// Do parenting stuff...

transform.localScale = originalScale;

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).