- Home /
I am having an issue with the rotation of a child
Greetings all, I am having an issue with the positio of a child. To start off with my main model was made in blender, I have two bones parented to the hand. One is at the bottom pointing up, the other is at the top facing down. The being with the thumb pointing vertical. I have a knife with a bone in the middle. When I was working in blender parenting the knife bone to the bladeup bone it would assume the postion of the parent bone and it would also assume the rotation of the bone. The same is true for the bladedn bone. The blade of the knife should point up if attached to the bladeup bone and down if attached to the bladedn bone. One thing of note; for some reason all of my blender meshes need a -90 rotation on the x axis - this is not a big deal and it is easily adjusted, I just wanted to put it out there. When I parent the bone of the knife to either bone in the hand the rotation is way off, also it seems to be parented to the top of the hand bone not the base of it. The rotation does not change with being parented to either bone it is pretty must the same with a minor difference in position. So far I have tried alot of different lines of code and most of them produce crazy results, the two hat are the most stable are:
transform.parent = up.transform;
transform.position = up.position;
transform.rotation = up.rotation;
and
transform.parent = up.transform;
transform.localPosition = Vector3(0, 0, 0);
transform.localEulerAngles = new Vector3(-90, 0, 0);
up and dn are script Transforms. I use javascript. I am wondering should I be using the local rotation on the up bone? is that even possible? or am I just way off?
I have also tried setting
transform.localPosition = up.localPosition;
transform.localRotation = up.localRotation;
and that is close to the right position and looks like the right rotation but it is not in his hand.
Answer by gump74 · Aug 22, 2013 at 03:23 AM
ok through random troubleshooting I was able to resolve the issue. One I had to go into blender and change the roll of the knife bone so that it was pointing away from the roll of the bone in the hand. this must be a bug in unity. then the following code puts it in the right position and the right rotation.
transform.localPosition = Vector3(0, 0, 0);
transform.localRotation = up.localRotation;
and that fixed it.
Your answer
Follow this Question
Related Questions
A node in a childnode? 1 Answer
How to change the pivot point of a mesh in script? 1 Answer
Disabling the Z axis? 1 Answer