Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Can't position object to match child object in rigged character

Discussion in 'Animation' started by omatase, Mar 11, 2017.

  1. omatase

    omatase

    Joined:
    Jul 31, 2014
    Posts:
    159
    I have a character that is casting a spell. While casting I want to put a charging effect in the palm of their hand. Since the character is rigged and animated and I want the effect to follow their palm I decided to create an empty game object and put it in the hierarchy of their skeleton such that when the hand moves so does this empty game object.

    Now I'm instancing a new prefab that has a few particle emitters on it and setting the transform.position of that particle system to the transform.position of my empty game object. The problem is that the two positions don't align perfectly. They're like a foot off from each other. It's odd because the empty game object is always perfectly positioned in his palm but when I do this in the Update method:

    Code (CSharp):
    1. _chargeEffect.transform.position = RightHandStandardAttackPosition.transform.position;
    it never lines up perfectly. It feels like the effect's center isn't lined up with the center of the visual but my VFX guy has already looked into and it looks correct to him so I'm thinking there's some sort of issue that happens when you parent a game object to a complex and in-motion animated structure where the position of the child object is being misreported.

    Here's an animation showing the two positions and the attributes in the inspector.

    https://gyazo.com/20521af86aea7872222a392d87787db2

    Any help is much appreciated!

    Edit --

    It's not a problem specific to the object I am using. If I just create a sphere primitive it has exactly the same issue.

    https://gyazo.com/9a408c1adb6256f112e5961078190afa
     
    Last edited: Mar 12, 2017
  2. omatase

    omatase

    Joined:
    Jul 31, 2014
    Posts:
    159
    Bumped
     
  3. TrickyHandz

    TrickyHandz

    Joined:
    Jul 23, 2010
    Posts:
    196
    You might want to try parenting the effect to the hand rather than just attempting to match position. See doing this helps at all:
    Code (csharp):
    1. _chargeEffect.transform.SetParent(RightHandStandardAttackPosition.transform);
    2. _chargeEffect.transform.position = Vector3.zero;
    That should ensure the object is at the origin point of your right hand rather than offset from the rig.

    Cheers,
    TrickyHandz
     
    DavidGeoffroy likes this.
  4. omatase

    omatase

    Joined:
    Jul 31, 2014
    Posts:
    159
    Thanks @TrickyHandz, I *may* have tried this already but I don't remember. I will try it and see if it's a workable solution.