Search Unity

Drag object (Move, Scale, Rotate) on surface in ARCore

Discussion in 'AR' started by sweetan, Apr 23, 2018.

  1. sweetan

    sweetan

    Joined:
    Nov 21, 2017
    Posts:
    17
    Hi,
    I want to create an object draggable(Move, scale, rotate) on the surface.
    please help me.
    Thank you.
     
    robrtoprz likes this.
  2. SyedImranUnity

    SyedImranUnity

    Joined:
    Apr 4, 2018
    Posts:
    16
    Hello Sweetan,
    I prefer to watch this video on till end.


    Regards,
    Syed Imran SA
     
  3. darklift

    darklift

    Joined:
    Apr 11, 2016
    Posts:
    4
    Would love an example implementation of this as well. The video above doesn't have a drag functionality from what I am aware. Can't test the project either since it's outdated.

    For Resize and Rotate, the lean touch free asset found on the asset store seems to be working for me.
     
  4. saiakhil46

    saiakhil46

    Joined:
    Mar 17, 2018
    Posts:
    3
    I tried lean translate for dragging assert on the detected plane but assert was moving up and down but not on the detected plane. So, anyone helps me out of it
     
  5. blanx

    blanx

    Joined:
    Feb 26, 2016
    Posts:
    73
    Lean+ is great for moving objects on a plane.
     
  6. RoyDaipayan

    RoyDaipayan

    Joined:
    Jun 27, 2018
    Posts:
    2
    Any updates on the drag and drop functionality on the detected planes in ARCore
     
  7. VeerpalK

    VeerpalK

    Joined:
    Jul 4, 2018
    Posts:
    14
    i worked on Lean Touch and its working fine but For multiple objects its not working like if we move one objects second also moves .Any idea how to tackle it?
     
  8. robrtoprz

    robrtoprz

    Joined:
    May 15, 2017
    Posts:
    9
    @VeerpalK Hi, I think that this script will help you, only move the object that you're touching.
    Make sure that your object have the Layer "Surface" and a collider.
    It doesn't need Lean Touch.

    Code (CSharp):
    1. private bool holding;
    2.  
    3.     void Start()
    4.     {
    5.         holding = false;
    6.     }
    7.  
    8.     void Update()
    9.     {
    10.  
    11.         if (holding)
    12.         {
    13.             Move();
    14.         }
    15.  
    16.         // One finger
    17.         if (Input.touchCount == 1)
    18.         {
    19.          
    20.             // Tap on Object
    21.             if (Input.GetTouch(0).phase == TouchPhase.Began)
    22.             {
    23.                 Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
    24.                 RaycastHit hit;
    25.  
    26.                 if (Physics.Raycast(ray, out hit, 100f))
    27.                 {
    28.                     if (hit.transform == transform)
    29.                     {
    30.                         holding = true;
    31.                     }
    32.                 }
    33.             }
    34.  
    35.             // Release
    36.             if (Input.GetTouch(0).phase == TouchPhase.Ended)
    37.             {
    38.                 holding = false;
    39.             }
    40.         }
    41.     }
    42.  
    43.     void Move()
    44.     {
    45.         RaycastHit hit;
    46.         Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(0).position);
    47.         // The GameObject this script attached should be on layer "Surface"
    48.         if (Physics.Raycast(ray, out hit, 30.0f, LayerMask.GetMask("Surface")))
    49.         {
    50.             transform.position = new Vector3(hit.point.x,
    51.                                              transform.position.y,
    52.                                              hit.point.z);
    53.         }
    54.     }
    55. }
     
    hongyixiao and SyedImranUnity like this.
  9. VeerpalK

    VeerpalK

    Joined:
    Jul 4, 2018
    Posts:
    14
  10. SyedImranUnity

    SyedImranUnity

    Joined:
    Apr 4, 2018
    Posts:
    16
  11. unity_f9OmpRw9XwwDIw

    unity_f9OmpRw9XwwDIw

    Joined:
    Feb 9, 2020
    Posts:
    1
    @robrtoprz
    How do I use that code? Creat a new code to add an object?
     
  12. Tarmack

    Tarmack

    Joined:
    Dec 16, 2016
    Posts:
    12
    This solution actually work when you are puttin your finger on a plane and the object in the same time, but if you touch the object without hiting the plane, it's not working so i don't think this is the best way to do that at all. (for exemple if you are sit on a chair and you placed something on your desk ( a light) then if you touch top of the light to move it, it wont work)