Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question How to automatically position characters in a "paired animation"

Discussion in 'Animation' started by dandantutorsgh, Oct 30, 2023.

  1. dandantutorsgh

    dandantutorsgh

    Joined:
    Feb 26, 2023
    Posts:
    2
    So, I got those animations in the Unity Store and they work fine if the character are aligned perfectly, however, I want to do those animations with the player and the npc, I already got the script to play an animation when the player presses a specific key and is close enough to the npc, my problem here is aligning them because I have no idea, as I am a beginner on Unity (Not on c# though). Maybe using IK? Would appreaciate some help as even chatgpt didnt help me out here haha.

    Aligned and non aligned animations gifs attached bellow.
     

    Attached Files:

  2. MattVer

    MattVer

    Joined:
    May 19, 2013
    Posts:
    16
    You will most likely have to 'slide' the characters to the correct position/offset so that the motions match.

    You can store the offset required for this animation pair, and then move either character to the proper spot using Vector3.MoveTowards or Vector3.Lerp.

    You can also achieve a similar/same result as using TargetMatching, you'd still need to know the offset, and most likely move the Root target. This however requires RootMotion to be enabled IIRC.
     
  3. dandantutorsgh

    dandantutorsgh

    Joined:
    Feb 26, 2023
    Posts:
    2
    The thing is, imagine the npcs are just wandering around, theres no way to hardcode all the positions so I'm still trying to know how I'll do it.
     
  4. MattVer

    MattVer

    Joined:
    May 19, 2013
    Posts:
    16
    You don't hardcode a position, you hardcode an offset.

    Hugging position requires that CharacterA and CharacterB are standing 1.25 meters in front of each other for the animation to 'fit'.

    Let's say you'll use CharacterA position as the 'anchor' for the animation to play.
    You'll then start the animation, and quickly slide CharacterB so that his position is CharacterA position + offset for the animation to play correctly.
     
    Yuchen_Chang likes this.