parent LookAt distorts skews the child object

Hello everybody,

Here is the problem I found:

I shoot an arrow toward an arrow, once the arrow hit the object I make that object child of the arrow, then I want to be able to pull the object with the arrow. I move the arrow toward the camera following the arrow’s TransformDirection back, and added a LookAt script to keep the butt of the arrow pointing the camera but then the child object gets all distorted and skew when the arrow is pointing to the camera and as get closer to the camera gets worse.

I know it has something to do with the rotation because when I remove the LookAt code, it doesn’t happen anymore.

Any suggestions?

Regards,
Carlos

This is a common mathematical issue that all transformation hierarchies suffer from.

Basically, any transform with a rotation and a parent somewhere up the hierarchy with non-uniform scaling will be sheared.

The only solution is to not have non-uniform scaling in Transforms with rotated children. This could be achieved in any of several ways:

  • Move the scaling all the way down the tree to the mesh and other objects that need non-uniform scaling. This will not solve your problem if you are parenting your second arrow all the way down the tree.
  • Change the models to have correct scaling in the mesh. If the scale is correct in the model, you will not need any scaling in the hierarchy. This will guarantee to solve your problem.
  • Avoid parenting the arrows. Parenting can always be avoided at the cost of having to update the transform of the would-be child yourself every frame. Inconvenient (and definitely my last choice), but would solve the problem.

Needless to say, it’s best to avoid non-uniform scaling altogether.

Thanks very much for your reply, I am sorry but when I said " I shoot an arrow to an arrow" I meant “I shoot an arrow to an object”. Anyway you reply is very usefull! I appreciate it. The objects I am using for all this are the primitive cubes of Unity3d, so I did scale them to given a rectangular shape, so if I use cubes without any scaling I shouldn’t have any problem? is that what you are saying? Thanks again!

Regards,
Carlos

That would solve it indeed, but you don’t need to be that drastic ;).

  • The problem only occurs with non-uniform scaling (scaling where x, y and z have different values from eachother).
  • The problem only occurs on children of the object with this non-uniform scaling.

Since your arrow won’t ever have children, you can keep its scaling as it is. Your body object will have children, so you can fix it by changing the scaling of the body to be uniform (its x,y and z are the same number).