- Home /
Rotation problems when I child a sword to players hand! (pictures within to clarify)
First, observe this image of the shoulder rotating correctly. It rotates properly along the joint, but the sword doesn't stay in his hand, because it is not a child of the hand:
now, I child the sword to the hand, so now the shoulder should rotate and the sword should stay in the hand, right? Not quite:
now for some reason, the shoulder pivots around the sword instead of the chest!
What's going on!?
Answer by zombience · Aug 16, 2013 at 03:44 PM
The sword is being interpreted as part of your bone structure, and so interfering with your animations.
I've had this problem in the past, and I've worked around it by doing this:
Make an empty game object. Make the sword a child of that object, and orient it so that the hilt is at the "center" of the empty object.
On the empty object, place a script that updates its location like so:
public Transform target;
void Update()
{
transform.position = target.position;
}
then drop the transform of the hand onto the "target" variable in the inspector for this game object. The game object will now lock to position wherever the hand is. you can adjust the location of the sword by moving it around in local space, relative to the parent object.
if you want it to follow rotation, you can add the line:
transform.rotation = target.rotation;
Your answer
Follow this Question
Related Questions
2d: Animating a child's transform will lock the Parent in place 0 Answers
How can I stop a parented object from resetting its transform when a parent animation play? 1 Answer
How do I rotate my parent object without rotating the child object? 0 Answers