Log in or register to post comments

Model AI and Animation Changes

September 15, 2020 - 2:39pm #1

Hello,

 

Let's say in my first image target I have dog, in idle animation.

 

My second image target is a person who is owner of the dog.

 

When AR camera detects the second image target and the person appears in the screen; what i need is the dog turn towards the owner, walk to him and lick him.

 

How can i add these animation changes and AI target finding to AR?

 

Many thanks

Model AI and Animation Changes

September 17, 2020 - 4:02am #3

Thank you very much!

Model AI and Animation Changes

September 16, 2020 - 11:31pm #2

Hi,

you can add this script to your dog object. Then drag your clips and objects into the right fields. Use an not animated parent object for the dog otherwise the position changes will not apply.

Call the ChangeAnim function from OnTargetFound() in your owner Image Target. Also for the Collision detection for the last animation change both objects need rigid bodies an colliders.

public AnimationClip walk;
    public AnimationClip lick;
    public GameObject dog;
    public GameObject owner;
    Animation anim;
    Vector3 direction;
    void Start()
    {
        anim = GetComponent<Animation>();
    }
    public void ChangeAnim()
    {
        anim.clip = walk;
        anim.Play();
        direction = Vector3.Normalize(owner.transform.position- dog.transform.position );
        dog.transform.SetParent(null, true);
    }
    void Update()
    {
        if(anim.clip == walk)
        {
            float speed = 0.001f;
            dog.transform.position = dog.transform.position + direction*speed;
        }
    }
    void OnCollisionEnter(Collision collision)
    {
        anim.clip = lick;
        anim.Play();
    }
Log in or register to post comments