- Home /
Having an object clip to its parent
Hi, all! I am currently working on a character. When I hit 'q', he draws his sword from his back, and when 'q' is hit again he places it back on his back. I have the sword be parented to the back/hand on a certain point in the animation. This is all fine and dandy, but the whole time, an idle loop plays in which the character breathes, thus moving his back. The sword changes its relative position a lot, and does not always end up in the hand. This is unpredictable an unacceptable. Is there any way for me to get the sword to clip onto the hand bone of my character? Thanks. And
Cheers! - YA
Answer by syclamoth · Nov 16, 2011 at 01:41 AM
When you set the parenting for the sword, make sure that it has the correct local rotation and position. If you can't predict exactly where the hand is going to be at the moment that you parent the sword to it, you'll have to put up with a one-frame position jump. If you make sure that the sword is in the right place at the moment it gets parented, you won't have any problems afterwards.
Your other option is to use some kind of IK solver on the hand, but that's getting a little more complex.
Is the sword-drawing animation able to be played when the character is running? If not, think about making it a full-body animation. That would solve the problem, too.
Yes. It is supposed to :( Also, this is impossible to predict, as I have to set the parenting to trigger at
if animation["DrawSword"].time > 2.5 && animation["DrawSword"].time < 2.7
for some reason, unity cannot pinpoint an exact time, which gives me erratic results.
Are you SURE there is no clipping method? Like somehow parenting it to the hand, but making sure it is at the center of the Hand Bone?
Could I just set the transform to the Hand Bone's transform?
Alright. I figured it out. I add empties parented to the hand and back with position/rotation of where I want to clip them to, and then I set the transform.position/transform.rotation of the sword to it. TADA! OBJECT CLIPPING!
Very good! That's kind of what I was telling you to do, but you worked it out anyway!
Your answer
Follow this Question
Related Questions
How to assign Transform to prefab ? 2 Answers
The position of the object and its changes! Help me can not understand! 0 Answers
How to Align the pieces with different scale? 0 Answers
How can I move an object physically correct around an other object? 1 Answer
Change Script so that the object's position can be modified in the Editor/through other scripts? 1 Answer