Search Unity

Move the game object position from animation for shadows

Discussion in 'Animation' started by pot2mayo, Oct 22, 2014.

  1. pot2mayo

    pot2mayo

    Joined:
    Dec 20, 2013
    Posts:
    5
    Hi,

    I have an animation in which the character moves forward while attacking.
    I also have a shadow projector in my character prefab located at my game object (0,0,0) position.
    The problem is that when the character moves forward in the animation (I'm not moving the game object at all), my shadow projector stays fixed and is not under my character anymore.

    Could you tell me what is the right way to handle this kind of problem?
    I thought there would be a way unity automatically adjusts the game object position from the animation data (e.g. vertex center of mass).

    Thanks!
     
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    You figure it out yet?
    If not let me know and I'll help you out.
     
  3. pot2mayo

    pot2mayo

    Joined:
    Dec 20, 2013
    Posts:
    5
    Hi,

    Thanks for your reply!
    I am still stuck on that :(

    I thought of a workaround to move my shadow but it looks like hell to setup and to maintain.
    I thought I could use animation curves to embed the offset of the shadow for each animation, then grab the float parameter in a script, and move the shadow sprite accordingly... kinda like they do in Unity's Mecanim tutorial to resize the character's collider during a jump (in the following video at 28m16s).



    But this is obvisouly too hacky to be the right way to do it...
    It'd be very helpful to get some guidance here.

    Thanks!
     
  4. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    You don't need code to accomplish this. Just make the projector a child of the character root. Even though the game object is not moving the root bone of the character is moving. This might look odd if the character's root rotates because the projector will inherit the rotation also so there are several ways to make the projector follow the transformation of the root and disregard the rotation. If you need I can explain a non coder way to do that too.
     
  5. pot2mayo

    pot2mayo

    Joined:
    Dec 20, 2013
    Posts:
    5
    Your explanation made me realize my mistake.
    I attached the shadow projector to the root of my prefab (which does not move), not to the root of my character's skeleton (Bip01). Changing this fixed everything.

    Thanks for your help!
     
  6. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,790
    Awesome! Glad I could help.