Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

【Look Animator】- Realistic look at target animation for your models!

Discussion in 'Assets and Asset Store' started by FimpossibleCreations, Sep 28, 2018.

  1. shamenraze1988

    shamenraze1988

    Joined:
    Nov 24, 2020
    Posts:
    208
    Yes share please.
     
  2. kdgalla

    kdgalla

    Joined:
    Mar 15, 2013
    Posts:
    4,615
    In my project, any object that a character would look at is called an "activator" (That includes other characters too). Change the name if you want.

    So each of these objects have

    ActivatorBase.cs
    Code (csharp):
    1.  
    2. public class ActivatorBase : MonoBehaviour {
    3.    public string label;
    4.    public Transform focalPoint;
    5. }
    6.  
    The focalPoint is for when you want a character to look at a specific part of the "activator". For example: if a character looks at another character, then they will look at that other character's face, so I'll put an empty game object at the character's face (attached to the head bone, maybe) and then assign that object's transform to the focalPoint. (If you leave it blank, then that means you just want characters to simply look at the activator's position.)

    Then for the character that has the Look Animator, I use this code:
    ActivatorAwareness.cs
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using FIMSpace.FLook;
    5.  
    6. public class activatorAwareness : MonoBehaviour {
    7.  Transform trans;
    8.    FLookAnimator FLA;
    9.  
    10.    // Use this for initialization
    11.    void Awake () {
    12.        trans = GetComponent<Transform>();
    13.        FLA = GetComponent<FLookAnimator> ();
    14.    }
    15.  
    16.    public float look_distance=10;
    17.    public LayerMask IgnoreLayer;
    18.  
    19.    void OnDisable()
    20.    {   StopAllCoroutines ();
    21.        if (FLA != null) {
    22.            FLA.SetLookTarget (null);
    23.        }
    24.    }
    25.  
    26.    void OnEnable()
    27.    {
    28.        StopAllCoroutines ();
    29.        StartCoroutine("ScanForActivators");
    30.    }
    31.  
    32.    IEnumerator ScanForActivators ()
    33.    { while (true)
    34.        {
    35.            ActivatorBase other_guy;
    36.            Collider[] hitColliders = Physics.OverlapSphere (trans.position,20,~IgnoreLayer.value);
    37.            float distance;
    38.            float shortest_distance;
    39.          
    40.            if (FLA != null)
    41.            {  
    42.                Transform new_target = null;
    43.                shortest_distance=look_distance;
    44.                for (int i=0; i < hitColliders.Length; i++)
    45.                { other_guy=hitColliders[i].gameObject.GetComponent<ActivatorBase>();
    46.                    if ((other_guy != null) && (other_guy.gameObject.GetInstanceID()!=gameObject.GetInstanceID()))
    47.                    {
    48.                        distance=Vector3.Distance(trans.position,other_guy.transform.position);
    49.                        if (distance<shortest_distance)
    50.                        {
    51.                            if (other_guy.focalPoint != null) {
    52.                                new_target = other_guy.focalPoint;
    53.                            } else {
    54.                                new_target = other_guy.gameObject.transform;
    55.                            }
    56.                            shortest_distance = distance;
    57.  
    58.                        }
    59.                    }
    60.                
    61.                }
    62.                FLA.SetLookTarget (new_target);
    63.              
    64.            }
    65.            yield return new WaitForSeconds(1);
    66.        }
    67.    }
    68.  
    69. } // Class end
    70.  
    71.  
    The code finds all of the colliders in a sphere and then compares the distance between ActivatorBase objects to find the closest one. The layer mask is for if you want to have a special layer just for activators.
     
    dsilverthorn likes this.
  3. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    537
    This might work for you, as kdgalla said, you can do all this things using additional script.
    You also have few examples for that in demo scenes package.

    About second question, can you send some screenshot?
    Are you sure "Lead Bone / Head" have assigned correct bone?

    Edit: Ahh I and kdgalla wrote reply in the same time? This messages was invisible for me before I posted :D
     

    Attached Files:

    shamenraze1988 likes this.
  4. shamenraze1988

    shamenraze1988

    Joined:
    Nov 24, 2020
    Posts:
    208
    For the first question, this script is working as I wanted. I will add later an option to look at the closet target or something but this is working fine for multiple targets.

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using FIMSpace.FLook;
    6.  
    7. public class Test : MonoBehaviour
    8. {
    9.     public FLookAnimator lookAnimator;
    10.     public Transform[] targets;
    11.     public float switchingTime;
    12.     public bool switchingLoop = false;
    13.  
    14.     private bool loopOnce = true;
    15.  
    16.     // Start is called before the first frame update
    17.     private void Start()
    18.     {
    19.         StartCoroutine(SwitchTargetsPeriodically());
    20.     }
    21.  
    22.     private void Update()
    23.     {
    24.  
    25.     }
    26.  
    27.     IEnumerator SwitchTargetsPeriodically()
    28.     {
    29.         for (int i = 0; true; i = (i + 1) % targets.Length)
    30.         {
    31.             if (i <= targets.Length - 1 && switchingLoop)
    32.             {
    33.                 loopOnce = true;
    34.  
    35.                 lookAnimator.ObjectToFollow = targets[i];
    36.             }
    37.  
    38.             if (switchingLoop == false && loopOnce)
    39.             {
    40.                 if (i <= targets.Length - 1)
    41.                 {
    42.                     lookAnimator.ObjectToFollow = targets[i];
    43.                 }
    44.                
    45.                 if(i == (targets.Length - 1))
    46.                 {
    47.                     loopOnce = false;
    48.                 }
    49.             }
    50.  
    51.             yield return new WaitForSeconds(switchingTime);
    52.         }
    53.     }
    54. }
    55.  
    about my second question, I will add some screenshots a bit later. The head and body are working fine with the look at the problem is with the finger/s.
     
  5. shamenraze1988

    shamenraze1988

    Joined:
    Nov 24, 2020
    Posts:
    208
    Here are some screenshots of my project.

    The first screenshot is of the finger of my player :
    and the hierarchy :



    On the player, I have two components of the Look Animator 2 script. the first is for the head the second for the finger.

    This screenshot is showing the inspector of the Look Animator 2 of the head settings :
    This is working fine the head and body are moving and the head is looking toward the target/s :



    Now the second Look Animator 2 component I dragged the finger to the Lead bone / Head :
    Then I hit twice on the + on the Additional Spine Bones :



    On the Tweak tab I dragged the following object target :



    Now I'm running the game: look at the player's fingers. The finger that should point looks broken and the rest of the fingers doesn't seem like the fingers position's like in your characters.



    I also tried other parts of the finger in the hierarchy to drag to the Lead bone / Head like the rig_f_index.02.L or the rig_f_index.01.L then pressed the + plus twice or even more than twice in all cases the fingers are not even close to what it looks like on your characters.


    I can record also a short video of the gameplay to show how it looks like if it will be more helpful.
     
  6. shamenraze1988

    shamenraze1988

    Joined:
    Nov 24, 2020
    Posts:
    208
    With this script, you can look at multiple targets and also select a specific targets to look at only.

    Code (csharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using FIMSpace.FLook;
    6.  
    7. public class MultipleLookAtTargets : MonoBehaviour
    8. {
    9.     public FLookAnimator lookAnimator;
    10.     public Transform[] targets;
    11.     public bool lookAtSpecificTarget = false;
    12.     public int lookAtSpecificTargetIndex;
    13.     public float switchingTime;
    14.     public bool switchingLoop = false;
    15.  
    16.     private bool loopOnce = true;
    17.     private bool startC = true;
    18.  
    19.     // Start is called before the first frame update
    20.     private void Start()
    21.     {
    22.         LookAtTargets();
    23.     }
    24.  
    25.     private void Update()
    26.     {
    27.         LookAtTargets();
    28.     }
    29.  
    30.     IEnumerator SwitchTargetsPeriodically()
    31.     {
    32.         for (int i = 0; true; i = (i + 1) % targets.Length)
    33.         {
    34.             if (i <= targets.Length - 1 && switchingLoop)
    35.             {
    36.                 loopOnce = true;
    37.  
    38.                 lookAnimator.ObjectToFollow = targets[i];
    39.             }
    40.  
    41.             if (switchingLoop == false && loopOnce)
    42.             {
    43.                 if (i <= targets.Length - 1)
    44.                 {
    45.                     lookAnimator.ObjectToFollow = targets[i];
    46.                 }
    47.  
    48.                 if (i == (targets.Length - 1))
    49.                 {
    50.                     loopOnce = false;
    51.                 }
    52.             }
    53.  
    54.             yield return new WaitForSeconds(switchingTime);
    55.         }
    56.     }
    57.  
    58.     private void LookAtTargets()
    59.     {
    60.         if (lookAtSpecificTarget && targets.Length > 0)
    61.         {
    62.             startC = true;
    63.  
    64.             if (lookAtSpecificTargetIndex >= 0)
    65.             {
    66.                 lookAnimator.ObjectToFollow = targets[lookAtSpecificTargetIndex];
    67.             }
    68.         }
    69.         else
    70.         {
    71.             if (startC)
    72.             {
    73.                 StartCoroutine(SwitchTargetsPeriodically());
    74.  
    75.                 startC = false;
    76.             }
    77.         }
    78.     }
    79. }
    80.  
     
    dsilverthorn likes this.
  7. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    835
    @shamenraze1988 thank you very much for the script! This will be very helpful in my scenes.:)
     
  8. vladpiranha

    vladpiranha

    Joined:
    May 10, 2015
    Posts:
    7
    I'm having interesting trouble using Look Animator to create an aiming 'sharpshooter' enemy. The setup and animation is easy and beautiful as always, but projectiles don't instantiate from the muzzle of the weapon as they should (I use the location of a child GameObject placed there). As you can see, even though the muzzle GameObject moves as it should, the offset never changes and projectiles are spawned at the original position of the GameObject before Look Animator is taken into account. When I use a really crude LootAt script to create a similar effect for testing, I don't have this problem. Has anyone else experienced this?
     
  9. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    537
    Hello, this projectile and muzzle flash effect being created in original position is Execution Order cause, object is created before Look Animator changes, you can simply fix it by putting Enemy's code for creating muzzle and projectile in LateUpdate() instead of Update()
     
  10. vladpiranha

    vladpiranha

    Joined:
    May 10, 2015
    Posts:
    7
    You were 100% correct. I'm an artist who is new to coding, so I appreciate the help. This is why I buy your products with confidence.
     
  11. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    835
    This is a Teaser for an upcoming project continuing the Apollo's Dream series.

    The video was made with Unity 2019 using this asset.
     
  12. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    835
    This video was made using this asset. Fantastic tools to bring our characters alive!



    Third in the Apollo’s Dream series, we make these for all people to find some peace and beauty in this world of chaos. We hope you enjoy it.
     
  13. anton88pro

    anton88pro

    Joined:
    Jul 20, 2017
    Posts:
    61
    Hello!
    I'm animating a human model using Puppet3d controls (including control for a head, which means it kind of removes a bone and use it's own control), but I also want to use Look Animator to make head animation more natural or when a player nearby, she looks at the player. However when I apply LA to the Puppet3d's head control, it makes a head look at a wrong direction.
    Here in screenshot you can see the results, where character is supposed to look at TV (and the top blue box on the model is a Puppet3d's head control).
    So my question is, can I combine the two assets (if yes, then how?) or is it like I can use only one of the tools for controlling the head?
    P.S.: I also saw some other person had a problem with Puppet3d+LA, but the solution didn't work for me.
    Снимок экрана (392).png
     
  14. TwinB

    TwinB

    Joined:
    Feb 14, 2016
    Posts:
    7
    Would this work for use on a player setup, so that it could drive a camera?
     
  15. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    537
    Issues like this often are caused by different execution order.
    You can try switching it by entering "FLookAnimator.cs" file, see "[DefaultExecutionOrder(-10)]" line (14th line) and change -10 value to 100000 then save file. Wait for compile and check if now it works.
    If not, you can try setting value to -100000 and check again.
    If it will not solve the issue, please tell, then I will need to reproduce your issue on my side to find solution.
     
    anton88pro likes this.
  16. anton88pro

    anton88pro

    Joined:
    Jul 20, 2017
    Posts:
    61
    Changing the value to 100000 did help indeed:D! Thank you!!
    Though in my specific case, the character still looks at a target a bit sidewise, but I believe, it's due to my animation or rigging issues, as Puppet3D's demo robot works just flawlessly with LA. Do you think tweaking Correction panel could help with sidewise look?
     
  17. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    537
    You will find many parameters to fix it in the "Correct" bookmark.
    You can try switching "Fixing Preset" to manual, but it is very hard to setup and requires knowledge about Vectors and quaternions, so I think it will be good to stay with "Parental.
    Then you can try toggling "Refreshing" and see if it solves the issue.
    If not and if head rotation always is a bit off (like constant angle value) you can adjust it with "Bones Rotation Corrections" and tweak the head bone rotation.
    Last things you can try is increasing "Override rotations" field on the bottom in "Correct" bookmark and "Hidden rare settings" tab.


    Can you give a bit more explanation what want you achieve?
    You want rotate camera with head, like in some cut-scene? If yes, then all you need to do is parent camera object with your model head transform.
     
    anton88pro likes this.
  18. eldvbear

    eldvbear

    Joined:
    Jul 21, 2016
    Posts:
    9
    @shamenraze1988
    Thank you so much for that script. I was able to easily integrate it with the Invector Third Person Controller and it's LockOn features. Made my life a boatload easier!
     
  19. JeffreyStrate

    JeffreyStrate

    Joined:
    Jul 27, 2016
    Posts:
    32
    Hi, can you build a timer no human looks at a person forever regards
     
  20. Davidjsap

    Davidjsap

    Joined:
    Aug 17, 2017
    Posts:
    11
    @FimpossibleCreations I'm having an issue that a few others have had in this chain, but the solution isn't helping me. I'm instantiating a bullet at the end of a gun which is a grandchild of the moving bones. I have changed the default execution order of the LookAnimator to every different value, positive and negative, and yet still, the bullet instantiation is happening in the wrong spot. It's using the position from before the look procedural animation. I have confirmed my bullet fire script is happening on LateUpdate as well, and have messed with its execution order as well.

    I have tried everything I can think of and am stuck. I need my bullet to correspond to the enemy's twist and turn.
    Thank you for any help
     
  21. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    835
    While reading this forum, I realized that I never put up our last video, Apollo's Dream IV, which uses the look asset throughout and has the most creatures yet in one of our films. I think this video shows the potential of what this asset can do. I use it in every video and game I create. It is simple to use and works as promised.
    The finale of the Apollo's Dream Series. If you haven't seen it yet, we hope you enjoy it.
    Original musical score was done by Teresa Silverthorn, who does the music for all of our videos.
     
  22. Parkjung2016

    Parkjung2016

    Joined:
    Jun 27, 2020
    Posts:
    1
    I use this asset for my game I'm making a satisfying game and I have a question about this asset.
    I used animation ligging to mix this asset with Unity animation ligging to position the human hand and gun, but it doesn't seem to work properly. When you turn on the look animator component, animation ligging works properly, but when you use both, the position of your hand becomes strange. How can I use the two Component together?
     
  23. FimpossibleCreations

    FimpossibleCreations

    Joined:
    Jun 27, 2018
    Posts:
    537
    Animation rigging for some cases will not work with any custom procedural animation plugin, because of the execution order.
    Custom Procedural animation can work on top of animation rigging, but not before it, meaning animation rigging don't have idea about look animator effect existence.

    The animation update order looks like: Keyframe Animation -> Animation Rigging -> Look Animator.
    So if you make aiming with animation rigging, then look animator will rotate spine/head after animation rigging aim.

    Also some approaches for Animation rigging are generating separate hierarchy, which can make two plugins working on other objects, breaking the animation. Custom procedural animation (like Look Animator) works directly on the source bones transforms.

    Solution would be first animating look animator -> then animation rigging hands aiming, but animation rigging not allows for that, at least in the lastest versions I tested.
    So it may be not possible to connect your use for animation rigging with Look Animator, but it should be possible if you would use other IK solution.

    Extra tip: If you need bullet creation position tho, it needs to be called after LookAnimator, so in LateUpdate() instead of the Update().
     
  24. Dobalina

    Dobalina

    Joined:
    Sep 6, 2013
    Posts:
    105
    I thought I'd share a solution to this issue between Look Animator and worldspace particles.
    Blue = local space particles
    Red = world space particles
    Green = world space particles, with a simple Playmaker "smooth look torwards" action.
    As you can see the red particles in world space don't respect the position or rotation of Look Animator. I came by this little script someone posted in another unity thread that resolved the red worldspace particles.
     

    Attached Files:

  25. dsilverthorn

    dsilverthorn

    Joined:
    May 14, 2017
    Posts:
    835
    Showing off what the Look Animator can do for your scene. This video was made using Look Animator to showcase some new music from Teresa Silverthorn. I created a swamp scene and used the look effect on various animals throughout the video.
    This tool make it easy to set the distance and speed of movement, as well as how far they turn and automatically finds all of the bones!
    Well worth the money for this or any Fimpossible Assets.