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

Making AR Object A auto move to AR Object B

Discussion in 'Vuforia' started by vanila_secret, Jun 6, 2018.

  1. vanila_secret

    vanila_secret

    Joined:
    Jun 6, 2018
    Posts:
    1




    I need example code to make a cat move to a rat auto when it saw a rat card but i do not know about code that make check about the distance between the two and if its less than 2 units i set the cat to move towards the target which in that case is the mouse using a Slerp Vector function

    please help
     
  2. JDMulti

    JDMulti

    Joined:
    Jan 4, 2012
    Posts:
    384
    It isn't that hard but it needs some C# code. You can do this:
    - Have a class controller with 2 transform references, one of the cat and one of the rat
    - You can check with Vuforia when an image target is active using it's API
    - If both are active, Vector3.Distance between the two positions using the 2 transforms
    - If distance is higher then 2, make the cat go Lerp to the Rat, you can do this by using the 2 stored transforms again.

    Some other things to keep in mind:
    - Move the cat to the rat when he's in sight, do that using a raycast
    - Add a box collider as groundplane to both cat and rat
    - Raycast from cat to rat positions, if it hits a groundplane, it's not in sight or same level, if it does, animate / Lerp
    - If rat image target is lost, make cat interrupt his Lerp and let him go back

    It's a simple idea but once you got it working you can make it better.